in src/modules/timestream_telemetry/lambda_function/udq_data_reader.py [0:0]
def _run_timestream_query(self, query_string, next_token, max_rows) -> dict:
"""
Utility function: handles executing the given query_string on AWS Timestream. Returns an AWS Timestream Query Page
see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/timestream-query.html#TimestreamQuery.Client.query
"""
LOGGER.info("Query string is %s , next token is %s", query_string, next_token)
try:
# Timestream SDK returns error if None is passed for NextToken and MaxRows
if next_token and max_rows:
page = self.query_client.query(QueryString=query_string, NextToken=next_token, MaxRows=max_rows)
elif next_token:
page = self.query_client.query(QueryString=query_string, NextToken=next_token)
elif max_rows:
page = self.query_client.query(QueryString=query_string, MaxRows=max_rows)
# skip empty pages returned by Timestream
# passing in MaxRows but no NextToken, if we have more than MaxRows available we get back a NextToken and no results, and reissue the query
while 'NextToken' in page and len(page['Rows']) == 0:
page = self.query_client.query(QueryString=query_string, NextToken=page['NextToken'], MaxRows=max_rows)
else:
page = self.query_client.query(QueryString=query_string)
return page
except Exception as err:
LOGGER.error("Exception while running query: %s", err)
raise err