Premise

This is a quick and dirty tutorial on how to get set up with the AWS EC2 API.

Credentials

Go to http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html and follow the instructions to get your access key and secret access key.

Install the CLI Component

For this to work, you’ll need python and pip. Once you’ve ensured both are installed, run this command:

pip3 install awscli

Generate your config and credentials file

Now that you have your credentials, go ahead and run this command:

aws configure

When prompted, plug in your Access Key and Secret Access Key. For the region name, choose from the list found on this page.

You will be searching for the section marked as Amazon API Gateway.

For the last option you’re prompted for, you can specify text, table, or json for your output format preference.

Export the params required for each terminal session

export AWS_ACCESS_KEY_ID=$(ruby -ne 'print $1 if ~/.*key_id = (.*)/' < "${HOME}/.aws/credentials" | rev | cut -c 1- | rev)
export AWS_SECRET_ACCESS_KEY=$(ruby -ne 'print $1 if ~/.*access_key = (.*)/' < "${HOME}/.aws/credentials" | rev | cut -c 1- | rev)
export AWS_DEFAULT_REGION=$(ruby -ne 'print $1 if ~/region = (.*)/' < "${HOME}/.aws/config" | rev | cut -c 1- | rev)

At this point you should be able to run commands like this:

aws ec2 describe-instances --output table

and get output.