Skip to content

Instantly share code, notes, and snippets.

@jcaxmacher
Created April 11, 2020 20:50
Show Gist options
  • Save jcaxmacher/4324d24dff67983dc06f773a41500d27 to your computer and use it in GitHub Desktop.
Save jcaxmacher/4324d24dff67983dc06f773a41500d27 to your computer and use it in GitHub Desktop.
AWS Incident Response Playbook (Jupyter Notebook)
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
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment