📘 Note
This document describes how ship AWS logs to an S3 bucket from Cloudwatch log-group using Lambda.
This guide will teach you how to crete a log stream from CloudWatch log groups to S3 bucket, to allow Hunters to access the logs. To complete the creation of the log streaming, follow all of the steps listed below:
Create an IAM Role for the lambda.
Make sure to grant the execution role withPutObject
permissions for the destination bucket.Open a text editor and create a file named
log_shipping.py
with the following contents:Zip the file and save it with the name
log_shipping.zip
.Use the following command, where the role is the Lambda execution role you set up in step 2:
Grant CloudWatch Logs the permission to execute your function. Use the following command, replacing the placeholder account with your own account and the placeholder log group with the log group to process:
Create a subscription filter using the following command, replacing the placeholder account with your own account and the placeholder log group with the log group to process:
(Optional) Test using a sample log event. At a command prompt, run the following command which will put a simple log message into the subscribed stream.
To see the output of your Lambda function, navigate to the Lambda function where you will see the output in /aws/lambda/cloudwatch_log_shipping
.