Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni alexcasalboni/handler.py
Last active Jun 17, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.