Skip to content

Instantly share code, notes, and snippets.

@kepstein
Created August 27, 2021 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kepstein/aa1ef2db2760593fc318d0cd78118562 to your computer and use it in GitHub Desktop.
Save kepstein/aa1ef2db2760593fc318d0cd78118562 to your computer and use it in GitHub Desktop.
Script to automatically change all gp2 volumes to gp3 with aws-cli
#! /bin/bash
region='us-east-1'
# Find all gp2 volumes within the given region
volume_ids=$(/usr/bin/aws ec2 describe-volumes --region "${region}" --filters Name=volume-type,Values=gp2 | jq -r '.Volumes[].VolumeId')
# Iterate all gp2 volumes and change its type to gp3
for volume_id in ${volume_ids};do
result=$(/usr/bin/aws ec2 modify-volume --region "${region}" --volume-type=gp3 --volume-id "${volume_id}" | jq '.VolumeModification.ModificationState' | sed 's/"//g')
if [ $? -eq 0 ] && [ "${result}" == "modifying" ];then
echo "OK: volume ${volume_id} changed to state 'modifying'"
else
echo "ERROR: couldn't change volume ${volume_id} type to gp3!"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment