Last active
October 1, 2020 02:06
-
-
Save peacing/6a27696b9d1e7abb53b5308497d556e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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