Skip to content

Instantly share code, notes, and snippets.

@ro6it
ro6it / lambda_function_ALBS3Logs_to_CloudWatchLogs.py
Created November 25, 2022 11:49 — forked from psa-jforestier/lambda_function_ALBS3Logs_to_CloudWatchLogs.py
A lambda function to stream Application Load Balancer logs dropped in S3 to CloudWatch Logs
'''
This function send Application Load Balancer logs to CloudWatch Logs. So you can use CloudWatch tools, like Insight or custom metrics.
By default, ALB log its access in gz file in S3, and there is no way yo send the log directly to a Log Group / Log Stream.
This lambda function is triggered on S3 "PUT" action (when ALB write its log file). It then download the file localy, unzip it, sort it, and stream it to a CloudWatch log groups.
Installation
Activate ALB logs, and indicate the S3 bucket and the prefix for the log files. Enable, on the bucket, the deletion of old log files