Last active
June 17, 2019 17:01
-
-
Save alexcasalboni/acef5a09f1994f92c06f233a9669d165 to your computer and use it in GitHub Desktop.
AWS CloudWatch Logs - Lambda handler
This file contains hidden or 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 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