Use the below command to generate a list of volume id’s of all detached EBS volumes.
aws ec2 describe-volumes --filter "Name=status,Values=available" --query "Volumes[*].{ID:VolumeId}"
To generate delete-volume statements for reviewing, run the below command:
for volume in `aws ec2 describe-volumes --filter "Name=status,Values=available" --query "Volumes[*].{ID:VolumeId}"`
do
echo "aws ec2 delete-volume --volume-id $volume"
done
To delete ebs volumes with status ‘available’, run the below command
for volume in `aws ec2 describe-volumes --filter "Name=status,Values=available" --query "Volumes[*].{ID:VolumeId}"`
do
aws ec2 delete-volume --volume-id $volume
done