Created
November 17, 2017 14:18
-
-
Save bushong1/359f91d02eebe327d264f15d3777674b to your computer and use it in GitHub Desktop.
A BASH function to shortcut removing an AMI and it's associated Snapshots
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
function aws-rm-ami-snap() { | |
if [[ ${1} == ami-* ]]; then | |
AMI_ID=${1} | |
SNAPSHOT_IDS=$(aws ec2 describe-images --filters Name=image-id,Values=${1} | jq '.Images[].BlockDeviceMappings[].Ebs.SnapshotId' | sed 's/"//g') | |
aws ec2 deregister-image --image-id ${AMI_ID} | |
for snapshot_id in ${SNAPSHOT_IDS}; do | |
aws ec2 delete-snapshot --snapshot-id ${snapshot_id} | |
done | |
else | |
echo "ERROR: Require \$1 to be an AMI ID, starting with 'ami-'" | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment