0% found this document useful (0 votes)
55 views

EC2 Commandline API Tools M

1. The document discusses how to use command line tools to manage Amazon EC2 resources. It outlines downloading and configuring the EC2 API tools, including setting environment variables for access keys, region, and other settings. 2. Example commands shown include describing regions and images, launching, terminating, and describing instances, creating and attaching volumes, and detaching volumes. 3. The commands demonstrate basic lifecycle management of EC2 compute and storage resources via the command line interface.

Uploaded by

Role
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

EC2 Commandline API Tools M

1. The document discusses how to use command line tools to manage Amazon EC2 resources. It outlines downloading and configuring the EC2 API tools, including setting environment variables for access keys, region, and other settings. 2. Example commands shown include describing regions and images, launching, terminating, and describing instances, creating and attaching volumes, and detaching volumes. 3. The commands demonstrate basic lifecycle management of EC2 compute and storage resources via the command line interface.

Uploaded by

Role
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

AMAZON EC2

Working with Command line / API tools

ANIL KUMAR
Command line /API tools with Amazon EC2

1. Download the command line tools from http://aws.amazon.com/developertools/351?


_encoding=UTF8&jiveRedirect=1
2. Unzip the downloaded ec2-api-tools.zip to a folder
3. Open a command window and set the environment variables
4. Set EC2_HOME variable to the folder where the api tools are stored. In my case it is
set EC2_HOME=D:\000 CLOUD\EC2\cmd-line-tool\ec2-api-tools-1.6.4

5. Update the PATH variable with api-tools -bin folder


PATH=%PATH%;D:\000 CLOUD\EC2\cmd-line-tool\ec2-api-tools-1.6.4\bin

6. Set Access and Secret keys


SET AWS_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXX
SET AWS_SECRET_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

7. Set EC2_URL and REGION


SET EC2_URL=https://ec2.us-east-1.amazonaws.com
SET EC2_REGION=us-east-1a

All REQUIRED ENV-VARIABLE SETTINGS:


SET EC2_CERT="D:\000 CLOUD\EC2\cmd-line-tool\ec2-api-tools-1.6.4\jpaacckeys\cert-
6H27B64KWLBVHTNHVRCU2TBICHQQFHWU.pem"
SET EC2_PRIVATE_KEY="D:\000 CLOUD\AWS\Keys\10-feb\key_test10feb.pem"
set EC2_HOME=D:\000 CLOUD\EC2\cmd-line-tool\ec2-api-tools-1.6.4
PATH=%PATH%;D:\000 CLOUD\EC2\cmd-line-tool\ec2-api-tools-1.6.4\bin
SET AWS_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SET AWS_SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SET EC2_URL=https://ec2.us-east-1.amazonaws.com
SET EC2_REGION=us-east-1a

8. Test the setup with the following command


D:\000 CLOUD\AWS\AUTO_SCALING\AutoScaling-1.0.61.1\bin>ec2-describe-regions -O
%AWS_ACCESS_KEY% -W %AWS_SECRET_KEY% -U %EC2_URL%

9. You may get an output similar to the following


REGION eu-west-1 ec2.eu-west-1.amazonaws.com
REGION sa-east-1 ec2.sa-east-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-2 ec2.us-west-2.amazonaws.com
REGION us-west-1 ec2.us-west-1.amazonaws.com
REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com

10. Describe AMIs using the command ec2-describe-images

11. Create an Instance from an AMI


ec2-run-instances -O %AWS_ACCESS_KEY% -W %AWS_SECRET_KEY% -U %EC2_URL% ami-
1624987f
RESERVATION r-fd78f49b 858741687818 default
INSTANCE i-4acbc537 ami-1624987f pending 0
m1.small 2012-10-16T16:05:05+0000 us-east-1b aki-88aa75e1
monitoring-disabled ebs
paravirtual xen sg-0f369767 default false

ec2-describe-instances
RESERVATION r-fd78f49b 858741687818 default
INSTANCE i-4acbc537 ami-1624987f ec2-54-242-144-218.compute-
1.amazonaws.com ip-10-85-42-185.ec2.internal running 0
m1.small 2012
-10-16T16:05:05+0000 us-east-1b aki-88aa75e1
monitoring-disabled 54.242.144.218 10.85.42.185 ebs
paravirtual xen sg-0f369767 default false
BLOCKDEVICE /dev/sda1 vol-959f65e8 2012-10-16T16:05:12.000Z
true

12. Delete an instance


ec2-terminate-instances i-4acbc537
INSTANCE i-4acbc537 running shutting-down

13. Create and attach a Volume


ec2-create-volume -s 1 G -z us-east-1b
VOLUME vol-0dfc0670 1 us-east-1b creating 2012-10-
16T16:18:47+0000 standard

ec2-describe-volumes
VOLUME vol-0dfc0670 1 us-east-1b available 2012-10-
16T16:18:47+0000 standard

ec2-attach-volume -i i-68e6e815 -d /dev/sdf vol-0dfc0670


ATTACHMENT vol-0dfc0670 i-68e6e815 /dev/sdf attaching 2012-10-
16T16:22:39+0000
ec2-describe-volumes
VOLUME vol-0dfc0670 1 us-east-1b in-use 2012-10-
16T16:18:47+0000 standard
ATTACHMENT vol-0dfc0670 i-68e6e815 /dev/sdf attached
2012-10-16T16:22:39+0000 false
VOLUME vol-7cf60c01 8 snap-96f7f4e2 us-east-1b in-use 2012-10-
16T16:21:31+0000 standard
ATTACHMENT vol-7cf60c01 i-68e6e815 /dev/sda1 attached
2012-10-16T16:21:31+0000 true
14. Detach a volume
ec2-detach-volume vol-0dfc0670
ATTACHMENT vol-0dfc0670 i-68e6e815 /dev/sdf detaching
2012-10-16T16:22:39+0000

15. Describe the volumes to ensure detachment

ec2-describe-volumes
VOLUME vol-0dfc0670 1 us-east-1b available 2012-10-
16T16:18:47+0000 standard
VOLUME vol-7cf60c01 8 snap-96f7f4e2 us-east-1b in-use 2012-10-
16T16:21:31+0000 standard
ATTACHMENT vol-7cf60c01 i-68e6e815 /dev/sda1 attached
2012-10-16T16:21:31+0000 true

You might also like