2

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.

user3073109
  • 27
  • 1
  • 8

3 Answers3

5

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

Nishant
  • 54,584
  • 13
  • 112
  • 127
  • i have set it as environment variables. But its not working however, i have not set EC2_PRIVATE_KEY, EC2_CERT variables? is this the issue ? how to set them ? – user3073109 Dec 06 '13 at 06:28
  • Do not bother just pass on `--aws-access-key --aws-secret-key ` with appropriate values with all of your commands. – Nishant Dec 06 '13 at 06:33
  • BTW, you should either pass the two variables I have mentioned in the command or you should set them as envt variable as said here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SettingUp_CommandLine.html – Nishant Dec 06 '13 at 06:37
  • @ when i am passing the secret key and access key explicitly them its working, otherwise its not working. i am setting it as environmental variable : `export AWS_ACCESS_KEY_ID=NXIEA export AWS_SECRET_ACCESS_KEY=F8odPLeozUqx` i dont want to pass the keys explicitly – user3073109 Dec 06 '13 at 06:40
  • What do you see when you do `echo $AWS_ACCESS_KEY` and `echo $AWS_SECRET_KEY`. If you get exactly what you are setting, you are doing it right. Else something wrong with the way you set them up. – Nishant Dec 06 '13 at 06:45
  • BTW the correct variables are `AWS_ACCESS_KEY` and `AWS_SECRET_KEY` not `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. – Nishant Dec 06 '13 at 06:47
  • yeah i have set the correct variables: i have set the env variables as: export EC2_BASE=/opt/ec2 `export EC2_HOME=$EC2_BASE/tools export AWS_ACCESS_KEY=AKI export AWS_SECRET_KEY=F8qx export PATH=$PATH:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:$EC2_HOME/bin export JAVA_HOME=/usr/lib/jvm/jre` – user3073109 Dec 06 '13 at 07:00
  • now i am getting this error: `ec2-describe-regions | sort Unknown problem connecting to host: 'us-west-2' Unable to execute HTTP request: us-west-2` – user3073109 Dec 06 '13 at 07:01
  • Did you try `ec2-describe-regions` without any pipe and without any parameter? It should work. But I guess you moved to a different tool. I guess that helped you, though it does not solves the problem stated in the question. – Nishant Dec 06 '13 at 08:32
  • no its not working. its working only if i specify credentials in the command. however, if i specify the credentials as env varibales, it is not working. Also i want to know if i require, cert, key to be set as env variables? – user3073109 Dec 06 '13 at 09:17
  • cert and private key are not required for this command. Read the doc for this command at the bottom. Can you tell what do you see when you run `echo $AWS_ACCESS_KEY` and `echo $AWS_SECRET_KEY`? – Nishant Dec 06 '13 at 09:32
  • @ i see my credentials that i have set in env variables? – user3073109 Dec 06 '13 at 09:37
  • do i require to set cert and private key parameters ? – user3073109 Dec 06 '13 at 09:59
  • nope. Read the doc please: http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeRegions.html ", we recommend that you start using your access key ID (-O, --aws-access-key) and secret access key (-W, --aws-secret-key) now, as the private key (-K, --private-key) and X.509 certificate (-C, --cert) won't be supported after the transition period elapses." – Nishant Dec 06 '13 at 10:02
  • its working now, i just needed to reestablish the session after making the changes in bashrc. – user3073109 Dec 06 '13 at 10:40
3

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.

slayedbylucifer
  • 22,878
  • 16
  • 94
  • 123
0

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
determinacy
  • 177
  • 1
  • 5