Skip to content

Instantly share code, notes, and snippets.

@mehdi89
Last active May 6, 2022 06:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehdi89/cba5ac72b6aac00c180b325ffcd4b04e to your computer and use it in GitHub Desktop.
Save mehdi89/cba5ac72b6aac00c180b325ffcd4b04e to your computer and use it in GitHub Desktop.
Change AWS instance type from terminal (stop -> change instance type -> start)
echo "instance id: $1"
echo "instance type: $2"
#2>&1 > /dev/null to suppress the cli output
echo "stopping instance"
aws ec2 stop-instances --instance-ids $1 2>&1 > /dev/null
echo "waiting for instance to stop"
aws ec2 wait instance-stopped --instance-ids $1
echo "changing instance type"
aws ec2 modify-instance-attribute --instance-id $1 --instance-type $2
echo "starting instance"
aws ec2 start-instances --instance-ids $1 2>&1 > /dev/null
echo "waiting for instance to start"
aws ec2 wait instance-running --instance-ids $1
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment