Last active
December 7, 2017 20:03
-
-
Save pmarques/8a4a91101ad568d34fc5982b71c71170 to your computer and use it in GitHub Desktop.
Useful AWS CLI snippets
This file contains 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
# Delete buckets tagged with a key | |
for bucket in `aws --profile mojintegration s3api list-buckets --query "Buckets[].Name" --output text` ; doecho -n "Bucket: [${bucket}]: " ; [ "$(aws --profile mojintegration s3api get-bucket-tagging --bucket "${bucket}" --query 'TagSet[?Key==`pm` && Value==`works`].Key' --output text 2>/dev/null)" == "pm" ] && echo -e "\033[31mdelete\033[0m" || echo -e "\033[32mkeep\033[0m" ; done | |
# Delte old logstreams from a logGroup | |
LOG_GROUP=a | |
for streamName in $(aws --profile mojintegration logs describe-log-streams --log-group-name "${LOG_GROUP}" --query 'logStreams[?lastIngestionTime <= `1502092833000`].logStreamName' --output text) ; do aws --profile mojintegration logs delete-log-stream --log-group-name "${LOG_GROUP}" --log-stream-name "${streamName}" ; done | |
# Delte log grouos which name starts with <LOG_GROUP> | |
for logGroup in $(aws --profile mojintegrations logs describe-log-groups --query "logGroups[?starts_with(logGroupName, \`${LOG_GROUP}\`)].logGroupName" --output text) ; do aws --profile mojintegrations logs delete-log-group --log-group-name "${logGroup}" ; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment