How much total storage is attached to your EC2?
Do you ever wonder what all the attached volumes add up to, for a given AWS EC2 instance? You can find that out with a single command via AWS CLI. You can also parameterize the command to add in to a loop and run for each EC2.
#set to your AWS profile pointing to the required account.
export aws_profile=stage
#This can be populated dynamically in a loop.
export instance_id=1-2012490
storage_size=$(aws ec2 describe-volumes \
--profile $aws_profile \
--filter Name=attachment.instance-id,Values=$instance_id \
--query 'Volumes[*].[Size]' --output text | paste -s -d"+"|bc)
The variable storage_size
will hold the sum of all the attached volumes in GB. The describe-volumes
command returns one row per attache volume with size in GB. Multiple rows need to be rolled up into a single line with paste
and then added by bc
.