I am trying to embed access and secret key along with aws cli. e.g.
aws ec2 describe-instances --aws-access-key --aws-secret-key
Its the best way and more secure to use IAM roles. There you can set specific rights to this instance and what it has to access in your account.
Depending on what awscli version you use you can use describe-instances in a couple ways.
Like this one:
ec2din -O your-key -W your-secret-key --region your-region
Also there is a big difference when you install awscli with pip install or from pkg like ubuntu deb package.
ec2din is a short command to ec2-describe-instances
More examples here: ec2-describe-instances
Regards.
I think the previous answers are correct, here is my response which is more like Danh response but also including multiple options and Windows too
export AWS_ACCESS_KEY_ID=your_key; export AWS_SECRET_ACCESS_KEY=your_secret; aws s3 ls
AWS_ACCESS_KEY_ID=your_key AWS_SECRET_ACCESS_KEY=your_secret aws s3 ls
$Env:AWS_ACCESS_KEY_ID="your_key"
$Env:AWS_SECRET_ACCESS_KEY="your_secret"
aws s3 ls
Full credit to great AWS document
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.
Another method is to use echo
with aws configure as a one-liner:
echo -ne '%s\n%s\n%s\n%s\n' <access_key> <security_key> <region> <output> | aws configure
To access aws through cli,
aws configure
I had to access multiple accounts on Amazon....so my solution:
under: ~/.aws/config
[default] aws_access_key_id = xxxx aws_secret_access_key = xxxxxx region=sa-east-1 output=text
[profile prof1] region=us-east-1 output=text aws_access_key_id = yyy aws_secret_access_key = yyyyy
[profile prof2] region=us-east-1 output=text aws_access_key_id = wwwwww aws_secret_access_key = wwwww
..and then when evoke the aws CLI, i passed the parameter "--profile" as:
/usr/local/bin/aws ec2 describe-security-groups --group-ids sg-xxxx --profile prof2
...that it!