Skip to content

Instantly share code, notes, and snippets.

@AstroTom
Created June 3, 2020 14:53
Show Gist options
  • Save AstroTom/5e60002af8175e68403b4300d3489f6c to your computer and use it in GitHub Desktop.
Save AstroTom/5e60002af8175e68403b4300d3489f6c to your computer and use it in GitHub Desktop.
#
# resize an ec2 between t3.medium and GPU g4dn.xlarge
#
AWS_INSTANCE_ID=i-0d286d48c371f57b1
TYPE=g4dn.xlarge
echo This will stop your instance $AWS_INSTANCE_ID to type $TYPE
# find name
echo Name tag is:
echo -e -n "\t"
aws ec2 describe-tags --filters "Name=resource-id,Values=$AWS_INSTANCE_ID" "Name=key,Values=Name" --output text|cut -f5
echo type is:
echo -e -n "\t"
aws ec2 describe-instances --instance-ids $AWS_INSTANCE_ID --query 'Reservations[*].Instances[*].InstanceType' --output text
read -p "This will stop and restart the instance. (Press Enter to continue)"
echo Stopping your instance.
aws ec2 stop-instances --instance-ids $AWS_INSTANCE_ID
#echo type is:
#echo -e -n "\t"
#aws ec2 describe-instances --instance-ids $AWS_INSTANCE_ID --query 'Reservations[*].Instances[*].InstanceType' --output text
aws ec2 modify-instance-attribute --instance-id $AWS_INSTANCE_ID --instance-type '{"Value": "'$TYPE'"}'
echo New type is:
echo -e -n "\t"
aws ec2 describe-instances --instance-ids $AWS_INSTANCE_ID --query 'Reservations[*].Instances[*].InstanceType' --output text
read -p "Do you want to start the instance? (Press Enter to continue, ^C to exit)"
echo "Restarting your instance with new size..."
aws ec2 start-instances --instance-ids $AWS_INSTANCE_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment