如何使用 AWS CLI 仅列出 AWS 组织下的账号和账户名称

mel*_*ous 3 amazon-web-services aws-cli aws-organizations

使用 AWS CLI,如何输出仅包含账户名称和帐号的所有账户的列表?

以下命令输出帐户名称和号码以及其他值,如何过滤它?

aws organizations list-accounts
Run Code Online (Sandbox Code Playgroud)

mel*_*ous 6

以下命令以表格格式输出帐户名称和帐号 -

aws organizations list-accounts --query 'Accounts[*].[Name, Id]' --output table
Run Code Online (Sandbox Code Playgroud)

输出:

----------------------------------------------------------------------
|                            ListAccounts                            |
+----------------------------------------------------+---------------+
|  alphabet-finance-dev                              |  80XX00000001 |
|  alphabet-security-prd                             |  80XX43500061 |
|  alphanet-devops-tst                               |  50XX00000046 |
|  ................                                  |  ............ |
+----------------------------------------------------+---------------+
Run Code Online (Sandbox Code Playgroud)

对于文本输出 -

aws organizations list-accounts --query 'Accounts[*].[Name, Id]' --output text
Run Code Online (Sandbox Code Playgroud)

对于 JSON 格式的输出 -

aws organizations list-accounts --query 'Accounts[*].[Name, Id]' --output json
Run Code Online (Sandbox Code Playgroud)

对于 YAML 中的输出 -

aws organizations list-accounts --query 'Accounts[*].[Name, Id]' --output yaml
Run Code Online (Sandbox Code Playgroud)