The main goal of this hands-on homework is to become faimilar with the Amazon elastic compute cloud (EC2) platform.
The exercise involves a series of steps. Please follow the instructions carefully to execute these steps. Each step provides familiarity with a certain functionality provided by EC2.
You will need security credentials (certificates and keys) to carry out the assignment. The TA will provide these credentials to you soon.
Please turn in a short (1-2 page) report with your observations and output from some of the key steps in this assignment. You will also required to provide an estimate (approximate estimates are OK) on how much your EC2 operations will cost the instructor. Use Amazon's pricing policy and monitoring data to compute your estimates.
In your report, you should clearly mention which EC2 api commands you tried, and All the AMI and instance IDs that you created.
Please remember that we are paying actual money to Amazon based on your usage -- so be very careful with the resources you use, and if you are unclear on any aspect, ask us for clarifications.
WARNING: All users in this class will be placed in the same security group - which means that you have privileges to terminate a server started by another fellow student. Please do not abuse these privileges.
We may add further explanations on some of these steps to clarify - we will notify the class by email if we do so.
export JAVA_HOME=/usr/lib/jvm/default-java export EC2_HOME=Location of ec2-api-tools export EC2_CERT=$EC2_HOME/groupID_cert.pem export EC2_PRIVATE_KEY=$EC2_HOME/groupID_pk.pem export AWS_ACCESS_KEY=your-aws-access-key-id (see below) export AWS_SECRET_KEY=your-aws-secret-key (see below) export PATH=$PATH:$EC2_HOME
-----BEGIN RSA PRIVATE KEY----- MIICXgIBAAKBgQDbH8TXzjL6jDTMC/mYfAb6kyUEbzqeQ/Ww94d3Gi/qwUq4nsL8 rjYBdAJb4H6hyJlHkNf339lr+JKBEzEN5fTXEjRGbSIs8pD3aVEg7DzD8I+vLZZ2 dj/yMmeM2DMaSdp86/W62fq5sXAFMmF7hpd2Yam1/RYJS6HrgRYppsEw7QIDAQAB AoGBAMX5FvRPVRmu0QjFjPUqoXeEt/4grFpPVkxT521BGKfFiUfyEIMQtrRrZrIx ytdKkMnq4GUQNrTpORwrBbfj2mdGDqJmXyVVrCYi+mENmsBWma9cozmdoq/HEe49 [only part of the key is listed for security reasons] -----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE----- MIIDYDCCAsmgAwIBAgIJAIztM80g1y3gMA0GCSqGSIb3DQEBBQUAMH4xCzAJBgNV BAYTAlVTMQswCQYDVQQIEwJNQTEQMA4GA1UEBxMHQW1oZXJzdDEOMAwGA1UEChMF VU1BU1MxCzAJBgNVBAsTAkNTMQ4wDAYDVQQDEwVDUzY3NzEjMCEGCSqGSIb3DQEJ ARYUcGxlYXNldGVzdEBnbWFpbC5jb20wHhcNMTEwMzA3MjEzOTMxWhcNMTEwNDA2 MjEzOTMxWjB+MQswCQYDVQQGEwJVUzELMAkGA1UECBMCTUExEDAOBgNVBAcTB0Ft aGVyc3QxDjAMBgNVBAoTBVVNQVNTMQswCQYDVQQLEwJDUzEOMAwGA1UEAxMFQ1M2 NzcxIzAhBgkqhkiG9w0BCQEWFHBsZWFzZXRlc3RAZ21haWwuY29tMIGfMA0GCSqG SIb3DQEBAQUAA4GNADCBiQKBgQDbH8TXzjL6jDTMC/mYfAb6kyUEbzqeQ/Ww94d3 [only part of the certificate is listed for security reasons] -----END CERTIFICATE-----
KEYPAIR group1 01:f8:73:c5:63:e7:02:50:a3:a9:xx:xx:xx:xx:xx:xx -----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAknnSdVJUuO1QBHV3/3eHw4OKUPtJ+fIgjuhxE0b/aMaSYADJh6zhnGoiSWFv rzEqxFjPXW1RlKao6/tj+rrBBYQcYH56YX/seQCPUzbfa3U0y/g/id9VN+thnwomWAHooKlWgJLa foDRpy5TaoS+ouhuV+Zme8qVCOrVd7iCb9ll+s+RrnakusKUYYz8kA6mUf+vGl/lbJZmHQgRMnaV +FyePvd88wbpJwXtweJCnDIuQe5gWHV9G/4EWCgtF0eoSvlbx2abhcwvTkSUeNStn3bEeTES3wAn 5CIwPLrWyZg+c0w/eM6yyM8E18Rygb2I3WuOuk9ZhwP0fyE9Emd4twIDAQABAoIBAFQ8PLz9qP1k dGTsDSNcYTYd2phxuvxDs1eb8xNL/CwMLjeJnFwrHt/t5WPf5fORSe/6xt4KtSTQp0p2muuhJMoA TLVtZwHVKG/503LelqPclo1KaXfneMGc2to0YxKvnlFusPFmAsNHX8pOCOi0CFH1ayeft4YvXX/w [only part of the key is listed for security reasons] -----END RSA PRIVATE KEY-----
AKIKI6YAKCM3UQLHOXJO DvUNt2aXZgGwoPw/2ZJK3TuyE8ZUdmduqZGarOB4 arn:aws:iam::101240882738:user/group1 FIAAI3QY3XPDSCJ2CPXEIThe first line is the access key, and the next one is the secret key. Insert the correct values from the files provided to you of the AWS access key and secret key in your .bashrc,
export AWS_ACCESS_KEY=AKI.... export AWS_SECRET_KEY=DvU....
$ ec2-describe-regions REGION eu-west-1 ec2.eu-west-1.amazonaws.com REGION us-east-1 ec2.us-east-1.amazonaws.com REGION ap-northeast-1 ec2.ap-northeast-1.amazonaws.com REGION us-west-1 ec2.us-west-1.amazonaws.com REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com
One can create an EC2 instance by specifying an ami-id. But before you create an instance you need to know what kind of ami to use. This is how you would do it
ec2-run-instances ami-22111148 -k KeyNameHere -t m1.small
ec2-describe-instances i-487587d5.This gives various details about the instance type, who is running it, and the address where you can access the instance, something like ec2-54-197-107-158.compute-1.amazonaws.com .
$ ssh -i groupX_pair.pem ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
$ cd $EC2_BASE $ unzip CloudWatch-2010-08-01.zip $ ln -s CloudWatch-1.0.9.5/ cloudWatch ## you will have to put things in .bashrc for edlab machines $ vi ~/.bash_profile export export AWS_CLOUDWATCH_HOME=$EC2_BASE/cloudWatch export export PATH=$PATH:$EC2_HOME/bin:$AWS_CLOUDWATCH_HOME/bin
$ mon-list-metrics CPUUtilization AWS/EC2 {InstanceId=i-e028d78f} CPUUtilization AWS/EC2
$ ec2-monitor-instances i-e06b948f i-e06b948f monitoring-pending
$ mon-get-stats CPUUtilization --period 60 --statistics "Average" --namespace "AWS/EC2" --dimensions "InstanceId=i-e06b948f" 2011-03-19 12:39:00 0.43200000000000005 Percent 2011-03-19 12:44:00 0.0 Percentmore details on using this api are available here
yum install -y perl java-1.6.0-openjdk.i386 firefox
$ mon-get-stats NetworkIn --period 60 --statistics "Average" --namespace "AWS/EC2" --dimensions "InstanceId=i-e06b948f" 2011-03-19 12:39:00 165.2 Bytes 2011-03-19 12:44:00 0.0 Bytes
ec2-create-image i-487587d5 -n 677_test_imageIf successful, this returns a new AMI, note down this ami-id.
$ ec2-describe-images | grep your-new-ami-id
ec2-terminate-instances instance-idYou can approximate the time it takes to terminate by looking at the ec2-describe-instances output and see the status of your instance (running/ shutting-down/ stopped/ terminated, etc)
$ ec2-run-instances new-ami-id -k groupKeyHere -t m1.small
ec2-deregister ami-id-here
ec2-describe-snapshots | grep ami-id-here SNAPSHOT snap-beba4fd9 vol-9ccd304d completed 2016-04-10T19:03:51+0000 100% 101840822718 8 Created by CreateImage(i-487587d5) for ami-9eddcdf4 from vol-9ccd304d
ec2-delete-snapshot snap-beba4fd