Script from taken from blog post Script to automatically change all gp2 volumes to gp3 with aws-cli
Created
August 27, 2021 23:17
-
-
Save kepstein/aa1ef2db2760593fc318d0cd78118562 to your computer and use it in GitHub Desktop.
Script to automatically change all gp2 volumes to gp3 with aws-cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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