Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing access and secret key aws cli

Tags:

aws-cli

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

like image 640
user3089927 Avatar asked Apr 28 '15 00:04

user3089927


People also ask

How do I log into AWS with access key and secret key command line?

Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/ . In the navigation pane, choose Users. Choose the name of the user whose access keys you want to create, and then choose the Security credentials tab. In the Access keys section, choose Create access key.

How do I pass a credential in AWS command line?

command line options: specify region, output format, or profile. Environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN. The AWS credentials file – located at ~/. aws/credentials on Linux, macOS, or Unix, or at C:\Users\USERNAME .

Can you use AWS CLI without access key?

However, if you would like to configure the AWS cli without using the Access/Secret Keys. Follow the below steps. Open the IAM console at https://console.aws.amazon.com/iam/. In the navigation pane, choose Roles, Create role.

How do I give access to AWS command line?

To switch to a production role (AWS CLI)Open a command prompt and set up your AWS CLI installation to use the access key from your IAM user or from your federated role. For more information, see Configuring the AWS Command Line Interface in the AWS Command Line Interface User Guide.


2 Answers

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.

like image 200
DanH Avatar answered Sep 24 '22 01:09

DanH


You can set credentials with:

aws configure set aws_access_key_id <yourAccessKey> aws configure set aws_secret_access_key <yourSecretKey> 

Verify your credentials with:

aws sts get-caller-identity 

For more information on set command:

aws configure set help 

General pattern is:

aws <command> help aws <command> <subcommand> help 

Note: Before overriding your credentials, you may want to keep a copy of it:

aws configure get aws_access_key_id aws configure get aws_secret_access_key 
like image 31
ulubeyn Avatar answered Sep 24 '22 01:09

ulubeyn