Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quiver/3f4da153bd5ac7509ce20036fc681e0c to your computer and use it in GitHub Desktop.
Save quiver/3f4da153bd5ac7509ce20036fc681e0c to your computer and use it in GitHub Desktop.
Bash Script to set retention periods for Lambda@Edge CloudWatch Logs in all regions.
#!/bin/bash
# L@E logs are displayed or stored in the Region closest to the location where the function executed.
# This Bash script sets retention periods for CloudWatch Log in all regions.
FUNCTION_NAME=LambdaAtEdgeFunctionName
LOG_GROUP=/aws/lambda/us-east-1.${FUNCTION_NAME}
# Possible Values: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, and 3653.
RETENTION_IN_DAYS=30
for region in `aws ec2 describe-regions --query 'Regions[].{Name:RegionName}' --output text`
do
echo ${region}
aws logs put-retention-policy --log-group-name $LOG_GROUP --retention-in-days $RETENTION_IN_DAYS --region ${region}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment