与 Amazon SDK或ListAccounts一起使用 CLI - Amazon Organizations
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 Amazon SDK或ListAccounts一起使用 CLI

以下代码示例演示如何使用 ListAccounts

.NET
Amazon SDK for .NET
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Uses the AWS Organizations service to list the accounts associated /// with the default account. /// </summary> public class ListAccounts { /// <summary> /// Creates the Organizations client and then calls its /// ListAccountsAsync method. /// </summary> public static async Task Main() { // Create the client object using the default account. IAmazonOrganizations client = new AmazonOrganizationsClient(); var request = new ListAccountsRequest { MaxResults = 5, }; var response = new ListAccountsResponse(); try { do { response = await client.ListAccountsAsync(request); response.Accounts.ForEach(a => DisplayAccounts(a)); if (response.NextToken is not null) { request.NextToken = response.NextToken; } } while (response.NextToken is not null); } catch (AWSOrganizationsNotInUseException ex) { Console.WriteLine(ex.Message); } } /// <summary> /// Displays information about an Organizations account. /// </summary> /// <param name="account">An Organizations account for which to display /// information on the console.</param> private static void DisplayAccounts(Account account) { string accountInfo = $"{account.Id} {account.Name}\t{account.Status}"; Console.WriteLine(accountInfo); } }
  • 有关API详细信息,请参阅 “Amazon SDK for .NET API参考 ListAccounts” 中的。

CLI
Amazon CLI

检索组织中所有账户的列表

以下示例演示了如何请求组织中的账户列表:

aws organizations list-accounts

输出包含账户摘要对象的列表。

{ "Accounts": [ { "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/111111111111", "JoinedMethod": "INVITED", "JoinedTimestamp": 1481830215.45, "Id": "111111111111", "Name": "Master Account", "Email": "bill@example.com", "Status": "ACTIVE" }, { "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/222222222222", "JoinedMethod": "INVITED", "JoinedTimestamp": 1481835741.044, "Id": "222222222222", "Name": "Production Account", "Email": "alice@example.com", "Status": "ACTIVE" }, { "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/333333333333", "JoinedMethod": "INVITED", "JoinedTimestamp": 1481835795.536, "Id": "333333333333", "Name": "Development Account", "Email": "juan@example.com", "Status": "ACTIVE" }, { "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/444444444444", "JoinedMethod": "INVITED", "JoinedTimestamp": 1481835812.143, "Id": "444444444444", "Name": "Test Account", "Email": "anika@example.com", "Status": "ACTIVE" } ] }
  • 有关API详细信息,请参阅Amazon CLI 命令参考ListAccounts中的。

有关 Amazon SDK开发者指南和代码示例的完整列表,请参阅使用 Amazon Organizations 用一个 Amazon SDK。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。