Skip to content

Instantly share code, notes, and snippets.

@brunopadz
Last active April 4, 2020 16:12
Show Gist options
  • Save brunopadz/6a9fec5f7189d0d4588a423428b7d4b0 to your computer and use it in GitHub Desktop.
Save brunopadz/6a9fec5f7189d0d4588a423428b7d4b0 to your computer and use it in GitHub Desktop.
Delete AWS Snapshots older than 15 days
DT=`date --date "-15 days" +"%Y-%m-%d"`
aws ec2 describe-snapshots --filters Name=description,Values="*OpsAutomator*" --query "Snapshots[?StartTime<='$DT'].{ID:SnapshotId}" | jq -r '.[] .ID' | while read rola; do
aws ec2 delete-snapshot --snapshot-id $rola && echo "ok" $rola || echo "not deleted"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment