Tuesday 15 November 2016

EC2 “On demand” instances start/Stop Automation:


1.       Create an IAM user and grant full access to the EC2 instances.

2.       Download the Access id and Secret key for the IAM user.

3.       Shell script to perform the start and stop

Start:

#!/bin/sh
ec2-start-instances i-“instance-id” i-“instance-id” -O “access-id” -W “secret-key”

Stop:

#!/bin/sh
ec2-stop-instances i-“instance-id” i-“instance-id” -O “access-id” -W “secret-key”

In the above script, you can add more instances-id’s to be restarted. The access id and secret key is of the IAM user performing the restart.

4.       Create a cronjob to run this on Friday evening to stop the instances and start it on Monday morning, so that you save lot of money on EC2 instances which are not used on weekends.


5.       The cron job should be run on an EC2 instance which is on the same subnet as all the instances which are to be restarted.

No comments:

Post a Comment