Skip to content

Instantly share code, notes, and snippets.

@chrisdpa-tvx
Last active October 18, 2017 15:19
Show Gist options
  • Save chrisdpa-tvx/e79743d83ae095675fafc744c9c4c4f6 to your computer and use it in GitHub Desktop.
Save chrisdpa-tvx/e79743d83ae095675fafc744c9c4c4f6 to your computer and use it in GitHub Desktop.
Remove unattached volumes
# 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