Last active
August 26, 2021 20:28
-
-
Save onuralp/3abdafbd8bf28f8f9143e520922177ec to your computer and use it in GitHub Desktop.
Update all AWS CloudWatch log groups retention policies with AWS CLI
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
#!/bin/bash | |
echo xxxxxxxxxxxxxxxxxxxxxx Updating Retention Policies xxxxxxxxxxxxxxxxxxxxxx | |
RETENTION_IN_DAYS=14 | |
AWS_REGION=us-west-2 | |
LOG_GROUPS=$(aws logs describe-log-groups --region $AWS_REGION | jq --raw-output '.logGroups|.[]?|.logGroupName') | |
for logGroup in $LOG_GROUPS | |
do | |
echo EXECUTING: "Updating retention policy for ${logGroup} with ${RETENTION_IN_DAYS} day(s)" | |
aws logs put-retention-policy --retention-in-days $RETENTION_IN_DAYS --region $AWS_REGION --log-group-name $logGroup | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment