This repository contains code to parse CloudFront logs from an S3 bucket and send the parsed data to OpenSearch.
mkdir package
pip3 install --target ./package opensearch-py user-agents
cd package
zip -r ../my_deployment_package.zip .
cd ..
zip my_deployment_package.zip lambda_function.py
Upload the generated zip file (my_deployment_package.zip) to AWS Lambda. Set the following environment variables in Lambda:
Set the following AWS and OpenSearch credentials as environment variables:
aws_access_key = ''
aws_secret_key = ''
opensearch_host = ''
opensearch_username = ''
opensearch_password = ''
To automatically trigger the Lambda function when new CloudFront logs are added to your S3 bucket, follow these steps:
- Navigate to the AWS S3 console.
- Select the S3 bucket containing your CloudFront logs.
- Go to the "Properties" tab and click on "Events."
- Add a new event configuration with the following settings:
- Event Name: Choose a descriptive name (e.g., "CloudFrontLogsEvent").
- Events: Select "PUT" event
- Prefix: (Optional) Specify a prefix if your CloudFront logs are stored in a specific folder within the bucket.
- Suffix: (Optional) Specify a suffix if your CloudFront logs have a specific file extension.
- Click "Add" to save the configuration.
Now, whenever new CloudFront logs are added to the specified S3 bucket, the Lambda function will be automatically triggered to parse and send the data to OpenSearch.
- Use serverless to deploy the lambda
- Add test cases to the code
- Create alerting when lambda fails