Skip to content

Instantly share code, notes, and snippets.

@oxidizeddreams
Last active September 14, 2018 19:03
Show Gist options
  • Save oxidizeddreams/900fb3626d986f16adc54451126e347d to your computer and use it in GitHub Desktop.
Save oxidizeddreams/900fb3626d986f16adc54451126e347d to your computer and use it in GitHub Desktop.
change volume_type for all EBS volumes in AWS
#!/bin/bash
while getopts "f:t:h:" option; do
case "${option}" in
f ) FILTERS=$OPTARG;;
t ) TYPE=$OPTARG;;
h )
echo "Usage:"
echo " ./aws-change-volumes-type -h Display this help message."
echo " ./aws-change-volumes-type -f 'Name=size,Values=5120' -t 'st1' "
exit 0
;;
\? )
echo "Invalid option: $OPTARG requires an argument" 1>&2
;;
esac
done
VOLUMES=$(aws ec2 describe-volumes --filter $FILTERS --query 'Volumes[].VolumeId[]' | grep vol | cut -d "\"" -f2)
#while IFS='' read -r line || [[ -n "$line" ]]; do
# aws ec2 modify-volume --volume-id $line --volume-type $TYPE --dry-run
#done < "$GATHER"
for volume in $VOLUMES; do
aws ec2 modify-volume --volume-id $volume --volume-type $TYPE --dry-run
if [ $? -eq 0 ]]; then
echo "$volume :: CHANGED;
else
echo "$volume :: UNCHANGED;
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment