Skip to content

Instantly share code, notes, and snippets.

@peacing
Last active October 1, 2020 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peacing/6a27696b9d1e7abb53b5308497d556e8 to your computer and use it in GitHub Desktop.
Save peacing/6a27696b9d1e7abb53b5308497d556e8 to your computer and use it in GitHub Desktop.
log_group = f'/aws/lambda/{lambda_function_name}'
query = "fields @requestId | " \
"sort @timestamp desc | limit 3 | " \
"filter @message like 'ERROR'"
time.sleep(180) # wait for logs to be available.
client = boto3.client('logs')
start_query_response = client.start_query(
logGroupName=log_group,
startTime=int((datetime.today() - timedelta(minutes=10)).timestamp()),
endTime=int(datetime.now().timestamp()),
queryString=query,
)
query_id = start_query_response['queryId']
time.sleep(5) # wait query to finish
response = client.get_query_results(
queryId=query_id
)
request_id = None
for result in repsonse['results']:
if result[0]['field'] == '@requestId':
request_id = result[0]['value']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment