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
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.
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 .
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With