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

时间:2021-05-22 01:58:38

标签: amazon-web-services aws-cli aws-organizations

使用 AWS CLI,我如何输出只有账户名称和账户号码的所有账户的列表?

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

aws organizations list-accounts

1 个答案:

答案 0 :(得分:1)

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

aws organizations list-accounts --query 'Accounts[*].[Name, Id]' --output table

输出:

----------------------------------------------------------------------
|                            ListAccounts                            |
+----------------------------------------------------+---------------+
|  alphabet-finance-dev                              |  80XX00000001 |
|  alphabet-security-prd                             |  80XX43500061 |
|  alphanet-devops-tst                               |  50XX00000046 |
|  ................                                  |  ............ |
+----------------------------------------------------+---------------+

用于文本输出 -

aws organizations list-accounts --query 'Accounts[*].[Name, Id]' --output text

用于 JSON 格式的输出 -

aws organizations list-accounts --query 'Accounts[*].[Name, Id]' --output json

用于 YAML 中的输出 -

aws organizations list-accounts --query 'Accounts[*].[Name, Id]' --output yaml