有没有办法列出可用/配置的 AWS CLI 配置文件?

Vil*_*lle 39 command-line amazon-web-services

除了解析~/.aws/config和/或~/.aws/credentials配置文件名称之外,有没有办法列出可用/配置的 AWS CLI 配置文件?

小智 33

您可以使用list-profiles以下命令在 aws 配置/凭证文件中列出配置文件:

aws configure list-profiles
Run Code Online (Sandbox Code Playgroud)

这对 aws-cli 版本 2.0.8 对我有用。

  • 这是 AWS CLI 2.x 中的新增功能。 (4认同)
  • 这应该作为 2020 年的答案而被修改 (3认同)

Vil*_*lle 15

(回答我自己的问题。)

不,那里没有。

我写了两个脚本,其中包括我最终使用的解析。对于任何感兴趣的人,可以在两个 GitHub 存储库中找到它们:

awscli-mfaaws-scripts

有两篇相关的博客文章:“重新访问 IAM 用户的 AWS CLI 密钥轮换脚本”和“ AWS CLI 中的简单 MFA 和配置文件切换”。

(更新 2019-01-27:博客文章“AWS CLI 中的轻松 MFA 和配置文件切换”已过时,因为它指的是awscli-mfa.sh脚本版本 1.x,而重写的 2.x 已发布。更新的博客文章是即将推出,但同时,请参阅awscli-mfa存储库文档)


小智 14

解析~/.aws/credentials对我来说很简单。

$ cat ~/.aws/credentials | grep -o '\[[^]]*\]'

=> [默认] [other_profile] [other_profile2]

我还通过将以aws-profiles下行添加到我的命令中,将命令别名为~/.bash_profile

alias aws-profiles="cat ~/.aws/credentials | grep -o '\[[^]]*\]'"
Run Code Online (Sandbox Code Playgroud)

使用配置文件

添加--profile <profile_name>到您的 aws 命令。前任。$ aws s3 cp ~/my.pdf s3://my_bucket/my.pdf --profile other_profile2