How to configure Amazon EC2 command line interface?

6.4k views Asked by At

I want to install Amazon Ec2 cli tools on a linux machine. I have configured java and have installed ec2 cli tools but I am getting the following error:

[root@ip-/]# ec2-describe-regions | sort Required option '-O, --aws-access-key KEY' missing (-h for usage)

Also please tell me how to set EC2_PRIVATE_KEY, EC2_CERT parameters. How to resolve this.

3

There are 3 answers

15
Nishant On BEST ANSWER

Option 1:

Set it as environment variable. Perhaps, append the following to your ~/.bashrc

export AWS_ACCESS_KEY=<your-aws-access-key-id>
export AWS_SECRET_KEY=<your-aws-secret-key>

If you do not want to do that, you may also type the above before you execute API commands.

Option 2:

Pass it with every command. Like this:

<command> --aws-access-key <aws_access_key_id> --aws-secret-key <aws_secret_access_key> [other opts]

for example:

ec2-run-instances ami-5da964c3  --aws-access-key AKIAIOSFODNN7EXAMPLE --aws-secret-key wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY 

You may also want to read the documentation: http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/command-reference.html

0
slayedbylucifer On

Ec2 cli tools are old and are not maintained by AWS anymore. Use aws-cli instead. Refer this link which details how to set-up and configure aws-cli.

using aws-cli, its a one time installation which support almost all the AWS Services. with older CLI tools, you had to configure CLI for each and every service seperately.

also aws-cli provides output in JSON format, hence it is extremely easy to parse output. This feature was missing from all the older CLI tools and parsing the output was the most painful task.

Also older CLI tools were java dependent, where as aws-cli works on python and in my experience, I have found its comparatively faster than the older cli tools.

0
determinacy On

There are two sets of AWS command lines tools. Here are the instructions for both:

In vi ~/.bashrc, add the following lines at the bottom: export AWS_ACCESS_KEY= && export AWS_SECRET_KEY=. Then run this command: source ~/.bashrc

Test that your aws tools are setup correctly:

ec2-describe-regions

Configure your AWS credentials with aws configure. See the AWS CLI configuration docs for more details and additional instructions.

Test that your aws tools are setup correctly:

aws ec2 describe-instances