Last active
June 8, 2021 09:51
-
-
Save alfallouji/5ad1a77ff81f6bf2895f1c6824173016 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
def query_aws_cloudwatch(query, log_group, region): | |
# Get a client | |
client = boto3.client('logs', region_name=region) | |
# Launch a query | |
start_query_response = client.start_query( | |
logGroupName=log_group, | |
startTime=int((datetime.today() - timedelta(hours=5)).timestamp()), | |
endTime=int(datetime.now().timestamp()), | |
queryString=query, | |
) | |
# Check if query has been completed | |
query_id = start_query_response['queryId'] | |
response = None | |
while response == None or response['status'] == 'Running': | |
print('Waiting for query to complete ...') | |
time.sleep(1) | |
response = client.get_query_results( | |
queryId=query_id | |
) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added comments