Automating AWS Server Instances

This document describes how to automate server instance start/stop on AWS using a script. This automation make servers up only when they need for specific hours, as per user wants.

Please follow the steps to automate.

  1. Create an IAM role called ec2-operator using the IAM console view. (http://docs.aws.amazon.com/IAM/latest/UserGuide/creating-

    role.html)

  2. Select the role type as “Amazon EC”.
  3. Set a custom policy to set permissions.
  4. Set a name for the policy and add the following to the python script.
    {
     "Statement": [
    
    {
     "Action": [
    
    "ec2:StartInstances", "ec2:StopInstances"

    “ec2:DescribeInstances”,

    ], "Effect": "Allow",
    
    "Resource": "*" }
    
    ] }

     

  5. Finish and create role.
  6. Start a new Amazon Linux AMI instance under the ec2-operator role.
  7. Login to the server and install the pre-requisites.
  8. $ yum install -y python26-pip gcc 
    $ pip install croniter
    $ yum update
    
    
  9. Copy the ec2_operator.py script to the server and change the permissions necessary.
  10. And edit the /etc/crontab for check the python script.
  11. Finally Tag the target instances for the start times using the regular time zone.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s