How to delete unused EBS volumes from AWS CLI to save on cost

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                                                                              
See also  How to disable Termination Protection on an EC2 Instance