2022-04-14 13:35:10 +00:00
|
|
|
#!/bin/bash
|
2022-07-07 12:51:41 +00:00
|
|
|
set -x
|
2022-04-14 13:35:10 +00:00
|
|
|
|
2022-05-23 14:12:09 +00:00
|
|
|
echo "Are you really sure as AMIs might be used by customers !!"
|
|
|
|
read
|
|
|
|
|
2022-07-07 12:51:41 +00:00
|
|
|
#TAG_FILTER="Name=tag:project,Values=zdt-alpine"
|
2022-08-17 15:20:49 +00:00
|
|
|
TAG_FILTER="Name=tag:Name,Values=zdt-alpine-3.16.2-x86_64-bios-tiny-minimal-r1"
|
|
|
|
#TAG_FILTER="Name=tag:Name,Values=zdt-alpine-3.16.2-x86_64-bios-tiny-kubezero-1.23.9-r0"
|
2022-04-14 13:35:10 +00:00
|
|
|
|
|
|
|
#for r in $(aws ec2 describe-regions --query "Regions[].{Name:RegionName}" --output text); do
|
2022-04-19 08:59:14 +00:00
|
|
|
for r in ap-southeast-2 ca-central-1 eu-central-1 us-east-1 us-west-1 us-west-2; do
|
2022-04-14 13:35:10 +00:00
|
|
|
amis=$(aws ec2 describe-images --region $r --owners self --output json --filters $TAG_FILTER | jq -r '.Images[].ImageId')
|
|
|
|
for a in $amis; do
|
|
|
|
aws ec2 deregister-image --region $r --image-id $a && echo "Deleted AMI $a in $r"
|
|
|
|
done
|
|
|
|
|
|
|
|
amis=$(aws ec2 describe-images --region $r --owners self --output json --filters Name=state,Values=failed | jq -r '.Images[].ImageId')
|
|
|
|
for a in $amis; do
|
|
|
|
aws ec2 deregister-image --region $r --image-id $a && echo "Deleted AMI $a in $r"
|
|
|
|
done
|
|
|
|
|
|
|
|
snapshots=$(aws ec2 describe-snapshots --region $r --owner-ids self --output json --filters $TAG_FILTER | jq -r '.Snapshots[].SnapshotId')
|
|
|
|
for s in $snapshots; do
|
|
|
|
aws ec2 delete-snapshot --snapshot-id $s --region $r && echo "Deleted snapshot $s in $r"
|
|
|
|
done
|
|
|
|
done
|