GithubHelp home page GithubHelp logo

ec2_custom's Introduction

EC2 custom scripts to automate starting and stopping of ec2 instances on Ubuntu

###Problem: AWS keeps charges for the free plans if you are not careful in managing the cpu time for your micro instance.

###Solution: Use scripting to stop the running instance at the end of the work day and start the instance at the beginning of the work day.

###Approach: Use the EC2 CLI api's to stop and start the instance. Use the Linux bash scripts to update the ssh config file.

###Assumption:

  1. These scripts assume that you are dealing with a single instance of the micro instance

  2. AWS EC2 console has been used to create a micro instance

  3. AWS EC2 console is used to create a security group to support ssh and other required protocols

  4. AWS EC2 console is used to create the security key file xxxx.pem file

  5. On Ubuntu dev box, ssh-keygen has been used to generate the proper keys

     Copy the xxxx.pem file from step# 4 to the $HOME/.ssh folder
    
     Create a "config" file with the entry for only one instance for example:
    
        Host helphd
    
        HostName ec2-11-222-333-44.us-west-2.compute.amazonaws.com
    
        User ubuntu
    
        IdentityFile "~/.ssh/xxxx.pem"
    
  6. git is installed and configured on the Ubuntu development box

Start and Stop ec2 instance using the scripts

To stop the instance type: $ ./stopec2.sh

To start the instance type: $ ./startec2.sh

To run the scripts above you need to do the following one time setup

BEGIN - ONE TIME SETUP

Setup ec2 cli api's for control from command line and scripting

  1. mkdir /usr/local/ec2

  2. cd /usr/local/ec2

  3. wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip

  4. unzip ec2-api-tools.zip #go to next step if ec2-api-tools-1.* directory exists

  5. rm ec2-api-tools.zip #remove the zip file as it is no longer needed

Download the ec2 custom scripts

  1. cd

  2. git clone [email protected]:cherukumilli/ec2_custom.git

  3. cd ec2_custom

Copy the pk*.pem, cert*.pem, rootkey.csv files from AWS to the "ec2_custom" folder

  1. Goto https://console.aws.amazon.com/iam/home?#security_credential

  2. Generate the Access Keys (Access Key ID and Secret Access Key)

  3. Download the Access Keys file. It is called rootkey.csv.

  4. Generate the X.509 Certificates

  5. Download the certicates. They start with pk-.pem and cert-.pem

  6. Copy all 3 files into the $HOME/ec2_custom foler

  7. open the file $HOME/ec2_custom/dotfiles/.ec2

  8. Edit entry AWS_ACCESS_KEY with the key from rootkey.csv (step #3)

  9. Edit entry AWS_SECRET_KEY with the key from rootkey.csv (step #3)

10.Edit entry EC2_URL with the URL region for your instance. Check http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SettingUp_CommandLine.html#set_ec2_url_linux for more info.

11.Edit the JAVA_HOME entry if needed. It currently pointing to: /usr/lib/jvm/java-7-openjdk-amd64/jre.

12.save the file

Update the start and stop scripts

a. Goto the AWS console: https://console.aws.amazon.com/console/home

b. Goto EC2 and create your instance if you haven't done so already

c. Copy the Instance ID (for example: i-1234567a)

d. Go to the $EC2_CUSTOM directory on your ubuntu dev box (cd $EC2_CUSTOM)

e. Replace the Instance ID place holder in startec2.sh and stopec2.sh with your Instance ID from step# c

f. save the files

Update your .bashrc file with the changes

./update_bashrc.sh

Restart all your shell windows for the changes to take effect

$ exit

!! HURRAY !!!

You are ready to use the ec2 custom scripts for starting and stopping your instance

ec2_custom's People

Contributors

cherukumilli avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.