Skip to content

Instantly share code, notes, and snippets.

@sajayantony
Created November 9, 2021 19:49
Show Gist options
  • Save sajayantony/3b4a5cf6809a174a5789c5c329d79c72 to your computer and use it in GitHub Desktop.
Save sajayantony/3b4a5cf6809a174a5789c5c329d79c72 to your computer and use it in GitHub Desktop.
Deleting EC2 volumes
#!/bin/bash
for REGION in $(aws ec2 describe-regions --output text --query 'Regions[].[RegionName]'| cat) ; do
echo $REGION
id=$(aws ec2 describe-volumes \
--filter "Name=status,Values=available" \
--query 'Volumes[*].[VolumeId]' \
--output text --region $REGION | cat) ;
echo $id
if [ -n "$id" ]; then
echo Deleting $id
aws ec2 delete-volume --volume-id $id --region $REGION | cat
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment