Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni
Last active June 17, 2019 17:01
Show Gist options
  • Save alexcasalboni/acef5a09f1994f92c06f233a9669d165 to your computer and use it in GitHub Desktop.
Save alexcasalboni/acef5a09f1994f92c06f233a9669d165 to your computer and use it in GitHub Desktop.
AWS CloudWatch Logs - Lambda handler
import time
import boto3
from decode import decode # see decode.py
cloudwatch_logs = boto3.client('logs')
def handler(event, context):
obj = decode(event['awslogs']['data'])
# wait for other logs to be collected in the stream
time.sleep(5)
full_logs = fetch_log_stream(obj)
# TODO also fetch x-ray traces based on request_id
# TODO create new issue on GitHub with logs and traces
return "OK"
def fetch_log_stream(obj):
return cloudwatch_logs.get_log_events(
logGroupName=obj['logGroup'],
logStreamName=obj['logStream'],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment