Shell Script to change Instance Type using AWS CLI
Normally, we use AWS Console to change instance type, say from t2.micro to m4.large, of particular instance which involves:
- Stopping the instance
- Right click and change the instance type
- Start the instance.
What if this has to be done at a time when you might be asleep or in a meeting, or in a movie theatre. There is no such thing known as “Work From Movie Theatre”.
This script will:
- Take 2 arguments, viz., instance ID and instance type
- Stop the instance
- Wait for instance to stop, and then change the instance type.
- Start the instance
Note: You have to configure AWS CLI with proper permissions in order to run the script.
The script can be copied from below. Don’t forget to modify as per your requirement.
Name the script file name as: changeInstanceType.sh
To set the cron, open crontab console:
Add the following line to schedule it for 26th January, 2017 at 10:30 PM (or 2230 hours):
30 22 26 01 * /bin/bash -x /path/to/script/changeInstanceType.sh i-abcd123 t2.medium >> /var/log/changeInstanceType.sh.log
Don’t forget to remove the cron tab, else it will run again, NEXT YEAR !
PS: May be there is a term “Work from Theatre“. (My Colleague :P )