Created
April 11, 2020 20:50
-
-
Save jcaxmacher/4324d24dff67983dc06f773a41500d27 to your computer and use it in GitHub Desktop.
AWS Incident Response Playbook (Jupyter Notebook)
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
import boto3 | |
import time | |
from datetime import datetime, timedelta | |
def execute_log_query(log_group, query, days_to_search): | |
start_time = int((datetime.today() - timedelta(days=days_to_search)).timestamp()) | |
end_time=int(datetime.now().timestamp()) | |
client = boto3.client('logs') | |
start_query_response = client.start_query(logGroupName=log_group,startTime=start_time,endTime=end_time,queryString=query,) | |
query_id = start_query_response['queryId'] | |
print ('Running...') | |
while True: | |
response = client.get_query_results(queryId=query_id) | |
if response['status'] != 'Running': break | |
time.sleep(3) | |
print (response['status']) | |
return response | |
def convert_dictionary_to_object(d): | |
o = {} | |
for f in d: | |
o[f['field']] = f['value'] | |
return o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment