【问题标题】:configure temp aws cli user still existing a default cli user配置临时 aws cli 用户仍然存在默认 cli 用户
【发布时间】:2022-01-16 20:02:25
【问题描述】:

如果.aws/ 路径中已有默认用户,如何配置临时 AWS-CLI 用户?如果我可以创建一个临时用户,我可以在不干扰默认用户的情况下测试我的任务!

【问题讨论】:

    标签: amazon-web-services config aws-cli temp


    【解决方案1】:

    您可以使用 AWS CLI named profiles:

    1. 创建一个名为 temp 的新配置文件,提供您的临时 CLI 用户的凭据:
    $ aws configure --profile temp
    AWS Access Key ID [None]: xxxxxxxxxxxxx
    AWS Secret Access Key [None]: yyyyyyyyyyyyy
    Default region name [None]: eu-central-1
    Default output format [None]: json
    
    1. 使用新创建的配置文件:
    $ aws s3 ls --profile temp
    

    在每个 AWS 调用中指定 --profile temp 并不方便,因此请考虑以下任何一种:

    • 在名为 AWS_PROFILE 的环境变量中指定配置文件:
    $ export AWS_PROFILE=temp
    $ aws s3 ls
    
    $ export AWS_PROFILE=another-profile
    $ aws s3 ls
    
    • 使用像awsp 这样的配置文件切换工具。有了它,切换配置文件(用户/角色)就像这样简单:
    $ awsp temp
    $ aws s3 ls
    
    $ awsp another-profile
    $ awsho
    $ aws s3 ls
    

    awsp 的好处是它支持自动完成功能,即使不记住个人资料名称,您也可以轻松地在个人资料之间切换。如果要检查当前配置文件,请使用:

    $ awswho
          Name                    Value             Type    Location
          ----                    -----             ----    --------
       profile                    temp              env    ['AWS_PROFILE', 'AWS_DEFAULT_PROFILE']
    access_key     ****************DHGY             shared-credentials-file
    secret_key     ****************O2pq             shared-credentials-file
        region                eu-central-1      config-file    ~/.aws/config
    

    【讨论】:

      【解决方案2】:

      您可以按如下方式添加临时用户:

      export AWS_ACCESS_KEY_ID=<your AWS_ACCESS_KEY_ID >
      export AWS_SECRET_ACCESS_KEY=<your AWS_SECRET_ACCESS_KEY>
      export AWS_REGION=<your AWS_REGION>
      

      当您设置这些值时,您将能够看到类似如下:

      {
          "Account": "2*********4", 
          "UserId": "A*****************V", 
          "Arn": "arn:aws:iam::275*******04:user/s3ba*****ser"
      }
      

      完成后,做剩下的:

      unset AWS_ACCESS_KEY_ID
      unset AWS_SECRET_ACCESS_KEY
      unset AWS_REGION
      

      【讨论】:

      • 这在 bash 脚本中很有用,例如CICD 管道。在您的 PC 上工作时,使用 awsp 会带来更愉快的体验(请参阅我的回答)
      【解决方案3】:

      您可以使用如下配置文件:

      $ aws ec2 describe-instances --profile user1

      查看 aws 文档here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-15
        • 1970-01-01
        • 1970-01-01
        • 2018-09-17
        • 1970-01-01
        • 2021-12-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多