Difference: EC2 (4 vs. 5)

Revision 52013-08-09 - geschd

Line: 1 to 1
 
META TOPICPARENT name="EmpiricalAlgorithmics"

Amazon's Elastic Compute Cloud (EC2)

Added:
>
>
 

Introduction

Amazon's Elastic Compute Cloud is a service which allows users to purchase computing resources by the hour in the form of virtual machine 'instances'. These instances are sold in many different sizes and under several purchasing options. Each instance is loaded with an Amazon Machine Image (AMI), a package including an OS and accompanying software. These can be chosen from a group of presets or customized by the user. When launching an instance, a startup script can be provided so that a task may be started immediately. Alternatively, the user may ssh to an instance and issue commands that way. Running instances may be monitored using Amazon's CloudWatch tools which can provide useful metrics such as CPU and network usage.
Line: 116 to 119
 
  • It should then run and finish in a few minutes. You will notice the Autoweka runs terminated improperly. This is because micro instances have too little memory to run Autoweka

CLI tools

Added:
>
>
In addition to the management console, there are also command line tools available. These allow you to launch and manage instances all from the command line. It also allow for easier handling of large, complex groups of instances through scripting. This section will walk through the use of the command line tools.

Setting up the CLI tools

  • Download and unzip the tools:
    • wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
    • unzip ec2-api-tools.zip
  • Next, you need to generate keys which will allow you to access your EC2 instances without being logged in through a browser
    • Go to the management console and select "Security Credentials" from the menu in the upper right-hand corner
    • On the Security Credentials page, go to "Access Keys" and select "Create New Root Key"
    • This will download a csv file containing both your "AWSAccessKeyId" and "AWSSecretKey"
  • Now we will need to set some environment variables
export EC2_HOME=/opt/ec2-api-tools-1.6.8.1(location of the unzipped ec2 tools)
export PATH=$PATH:$EC2_HOME/bin(add the directory to your path)
export AWS_ACCESS_KEY=ABCDEFGHIJKLMNOPQRST(value of "AWSAccessKeyId" downloaded earlier)
export AWS_SECRET_KEY=abc123DEFghiJKL456789+mnoPqRsTUV0wxyZ123(value of "AWSSecretKey" downloaded earlier)
export EC2_URL=https://ec2.us-west-2.amazonaws.com(The URL of your default EC2 region. Can be found here)
  • Everything should now be set up to use

Using the CLI tools

  • Now that the CLI tools have been set up, we will use them to launch an instance
  • If your PATH has been set properly, the commands can be used from anywhere. All commands begin with "ec2"
  • To launch an instance, we will use the command "ec2-run-instances" or the short form "ec2run"
  • The full command will resemble this: "ec2run ami-0358ce33 -t t1.micro -n 1 -k ec2DemoKey -g sg-565ab739"
    • "ami-0358ce33" specifies the AMI to use. This is the ID for the Amazon Linux AMI
    • "-t t1.micro" specifies what type of instance we wish to launch
    • "-n 1" indicates that we want to launch a single instance
    • "-k ec2DemoKey" specifies the key that this instance requires to connect
    • "-g sg-565ab739" specifies the security group the instance uses. This is the ID for the "quick-start-1" group
  • After executing this command, output will be generated, giving all the generated instance's properties. Check the management console to verify the instance is launching

  • A full listing and description of the commands can be found here: Commands (CLI Tools)
  • A quick reference card for common commands can be found here: Reference Card
  • All commands provide usage information if "-h" is used on the command line

Working from an Instance

This section presents some useful information about ways to use EC2 instances

User Data Scripts

  • When launching an instance, the "User Data" field may be utilized to pass any information to an instance
  • This data can then be read from within the instance (next section) or executed as a script on startup
  • Anytime the user data begins with the characters "#!", it will be run at startup under the root user
  • From command line, user data can be provided inline with "-d" or as a file with "-f"
  • The following script provided as user data will execute the quick start instructions from above automatically:
#!/bin/bash
sudo yum -y update
curl -L https://get.rvm.io | bash -s stable --ruby
source /home/ec2-user/.rvm/scripts/rvm
wget www.cs.ubc.ca/~hutter/AC_on_the_Cloud.tar.gz
tar xzvf AC_on_the_Cloud.tar.gz
cd AC_on_the_Cloud
ruby scripts/blackbox_evaluator.rb -f

Accessing Instance Metadata

  • Information about an instance such as AMI, instance ID, and user data can be accessed from within the instance itself
  • The following examples show various pieces of information that can be accessed:
GET http://169.254.169.254/latest/user-data
GET http://169.254.169.254/latest/meta-data/ami-id
GET http://169.254.169.254/latest/meta-data/instance-type
GET http://169.254.169.254/latest/meta-data/instance-id
  • Using just "http://169.254.169.254/latest/meta-data" will list names of the pieces of meta-data that can be accessed

CLI Tools on instances

  • If your instance is running the Amazon Linux AMI, it will have the CLI Tools already installed
  • The keys and region will not be set
  • You can either set the environment variables for "AWS_ACCESS_KEY", "AWS_SECRET_KEY", and "EC2_URL" or
  • You can provide these as command line options with each command: "-O, --aws-access-key", "-W, --aws-secret-key", and "-U, --url"
  -- Main.geschd - 08 Aug 2013
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback