AWS_ACCESS_KEY=your access key
AWS_SECRET_KEY=your real secret keyThis might look something like the example key below
EC2_URL=https://ec2.us-west-2.amazonaws.comNow, download and install the EC2 API Tools, because they are the easiest to install and start testing with:
ec2-describe-regions -O $AWS_ACCESS_KEY -W $AWS_SECRET_KEYand also, since they are set in your environment, you may omit them and just type
The example mentioned above is the EC2 API Java Client Tools, also called the "CLI tools", and formally refered to as "Amazon EC2 API Tools" available here http://aws.amazon.com/developertools/351. The official description is:
"The API tools serve as the client interface to the Amazon EC2 web service. Use these tools to register and launch instances, manipulate security groups, and more. "
Also, "Note: the API tools do not include the AMI tools. The AMI tools are used for bundling and uploading AMIs".
The somewhat similarly named cli toolset just for managing AMI instances is called the "Amazon EC2 AMI Tools". These AMI tools ( not API as above ), are specialized in managing, uploading, downloading AMIs. The official description is:
Note the the API tools do not include the functionality of the AMI tools. Also, the AMI tools are written in Ruby, not Java.
There is also a third major toolset for EC2, called "AWS Command Line Interface (CLI)". These are written in Python and are available here http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html#install-bundle-other-os
Name Command Location Language ---- ---------------- -------- AWS CLI ~/.local/lib/aws/bin/aws help Python EC2 API /usr/local/ec2-api-tools/bin/ec2-version Java EC2 AMI Tools ~/ec2-ami-tools-1.5.2/bin/ec2-ami-tools-version RubyOnce you have the AWS CLI installed you must simply configure it like so:
$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-west-2 Default output format [None]: jsonThose values are just examples from docs.aws.amazon.com. Of course use your own values for each of those.
See creating an AMI.
You can pick an Amazon supported Linux AMI here: http://aws.amazon.com/amazon-linux-ami/
It will also come with necessary tools to manage EC2 resources. For US-West Oregon, I will choose the the PV EBS-Backed 64-bit AMI: ami-b8f69f88.
Let's start with the the EC2 API Java tools.
I have an existing AMI, publicly provided, which I no longer want to use, so let's list it to grab the AMI id, then delete it.
ec2-describe-imagesNote the ec2-describe-images command has other options, for example, -all to list all available AMIs. That is more than 44,000 lines of output. By default, it lists just your images you have in storage.
Now let's detach that so we no longer are paying for it to be stored.
ec2-deregister ami-203f5010Now re-run ec2-describe-images and notice it no longer appears in the default api response. Second, let's get this new AMI into our account so we can start to work with it.
I found the cli options a bit challenging, so I used the Amazon web interface instead. I think the cli would be:
ssh firstname.lastname@example.org -p 80 -i ~/.ssh/aws_rsa
Note that I already have a key pair saved on Amazon and I use it to login to that instance. What about if I have a new instance, even from a new AMI I want to use that same key with?I will need to start the instance with the key specified as follows
aws ec2 run-instances --image-id ami-b8f69f88 --count 1 --instance-type t1.micro \ --key-name aws_rsa --security-group-ids sg-c7a86aa2 --subnet-id subnet-ea8aae81
In the above example, I use my existing key which is named, aws_rsa.
For a slick introduction to AWS and continuous deployment, see http://www.devopscloud.com/.