AWS Cli同时配置海外区和中国区的凭证

444 阅读1分钟

AWS Cli 是AWS的命令行工具,能帮助我们轻松的使用命令行来操作AWS的资源,通常我们使用AWS的时候同时会使用海外区和中国区,这时我们需要在一台电脑上同时使用不同的AWS credentials。我们可以aws profiles来作区分

设置海外区

我们可以显示的配置profile的参数,作为默认配置。

thinktik@thinkdesk:~$ aws configure
AWS Access Key ID [None]: AKIxxxxxxxxxR4IZ
AWS Secret Access Key [None]: SPdLxxxxxxxG6o04QvrB
Default region name [None]: us-east-1
Default output format [None]: json
thinktik@thinkdesk:~$ 

设置中国区

我们可以显示的配置profile的参数,给它一个值cn,做一些区分。

thinktik@thinkdesk:~$ aws configure --profile cn
AWS Access Key ID [None]: AKIA2xxxxxxPJ2BD
AWS Secret Access Key [None]: lcC5dmSIxxxxxxvWFs25D0Yl
Default region name [None]: cn-northwest-1
Default output format [None]: json

测试

我们做一个测试

# 查询AWS海外区的S3 bucket
thinktik@thinkdesk:~$ aws s3 ls
2022-06-15 13:34:09 aws-xxx-devops
2022-08-04 17:20:35 aws-xxx-front
# 查询AWS中国区的S3 bucket
thinktik@thinkdesk:~$ aws s3 ls --profile cn
2022-06-15 13:40:09 aws-cn-xxx-devops