如果.aws/
路径中已有默认用户,我如何配置临时AWS-CLI用户???如果我可以创建一个临时用户,我就可以在不干扰默认用户的情况下测试我的任务!!
您可以使用如下配置文件:
$ aws ec2 describe-instances --profile user1
看看这里的aws文档
您可以按如下方式添加临时用户:
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
您可以使用AWS CLI命名的配置文件:
- 创建一个名为
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
- 使用新创建的配置文件:
$ 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