passing access and secret key aws cli

前端 未结 11 929
旧巷少年郎
旧巷少年郎 2020-12-24 01:06

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 

        
相关标签:
11条回答
  • 2020-12-24 01:24

    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.

    0 讨论(0)
  • 2020-12-24 01:33

    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

    Linux/Mac

    export AWS_ACCESS_KEY_ID=your_key; export AWS_SECRET_ACCESS_KEY=your_secret;  aws s3 ls 
    

    Another way to skin a cat for Linux/Mac

    AWS_ACCESS_KEY_ID=your_key AWS_SECRET_ACCESS_KEY=your_secret aws s3 ls 
    

    Windows Powershell

    $Env:AWS_ACCESS_KEY_ID="your_key"
    $Env:AWS_SECRET_ACCESS_KEY="your_secret"
    aws s3 ls  
    

    Full credit to great AWS document

    0 讨论(0)
  • 2020-12-24 01:34

    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.

    0 讨论(0)
  • 2020-12-24 01:35

    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
    
    0 讨论(0)
  • 2020-12-24 01:37

    To access aws through cli,

    aws configure
    
    0 讨论(0)
  • 2020-12-24 01:41

    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!

    0 讨论(0)
提交回复
热议问题