passing access and secret key aws cli

user3089927 picture user3089927 · Apr 28, 2015 · Viewed 55.4k times · Source

I am trying to embed access and secret key along with aws cli. e.g.

aws ec2 describe-instances --aws-access-key <access_key> --aws-secret-key <secret_key>

Also tried with -o and -w options for access and secret key respectively. It says : Unknown option aws-access-key and aws-secret-key

Answer

DanH picture DanH · Feb 8, 2017

You can provide keys on the command line via envars:

AWS_ACCESS_KEY_ID=ABCD AWS_SECRET_ACCESS_KEY=EF1234 aws ec2 describe-instances

See http://docs.aws.amazon.com/cli/latest/topic/config-vars.html#credentials

EDIT: @wisbucky noted this could leave secrets in your command history. One way around this in bash at least I think is to prepend your command with a blank space and the command should not propagate to your bash history.