Last active
October 18, 2017 15:19
-
-
Save chrisdpa-tvx/e79743d83ae095675fafc744c9c4c4f6 to your computer and use it in GitHub Desktop.
Remove unattached volumes
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
# Remove any volumes that are not attached to an AWS instance | |
aws ec2 describe-volumes | \ | |
jq -r '.Volumes[] | select( (.Attachments|length)==0 ) | .VolumeId ' | \ | |
xargs -J % -n 1 aws ec2 delete-volume --volume-id % | |
# Remove DB snapshots that are older than a month | |
aws rds describe-db-snapshots | \ | |
jq -r ".DBSnapshots[] | select( (.SnapshotCreateTime<\"$(date -v-1m -u +%Y-%m-%dT%H:%M:%S.000Z)\") and (.SnapshotType==\"manual\")) | .DBSnapshotIdentifier" | \ | |
xargs -J % -n 1 sts aws rds delete-db-snapshot --db-snapshot-identifier % |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment