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

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

与 Amazon SDK或ListOrganizationalUnitsForParent一起使用 CLI

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

.NET
Amazon SDK for .NET
注意

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

using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Lists the AWS Organizations organizational units that belong to an /// organization. /// </summary> public class ListOrganizationalUnitsForParent { /// <summary> /// Initializes the Organizations client object and then uses it to /// call the ListOrganizationalUnitsForParentAsync method to retrieve /// the list of organizational units. /// </summary> public static async Task Main() { // Create the client object using the default account. IAmazonOrganizations client = new AmazonOrganizationsClient(); var parentId = "r-0000"; var request = new ListOrganizationalUnitsForParentRequest { ParentId = parentId, MaxResults = 5, }; var response = new ListOrganizationalUnitsForParentResponse(); try { do { response = await client.ListOrganizationalUnitsForParentAsync(request); response.OrganizationalUnits.ForEach(u => DisplayOrganizationalUnit(u)); if (response.NextToken is not null) { request.NextToken = response.NextToken; } } while (response.NextToken is not null); } catch (Exception ex) { Console.WriteLine(ex.Message); } } /// <summary> /// Displays information about an Organizations organizational unit. /// </summary> /// <param name="unit">The OrganizationalUnit for which to display /// information.</param> public static void DisplayOrganizationalUnit(OrganizationalUnit unit) { string accountInfo = $"{unit.Id} {unit.Name}\t{unit.Arn}"; Console.WriteLine(accountInfo); } }
CLI
Amazon CLI

检索父 OU 或根目录OUs中的列表

以下示例向您展示了如何获取指定根目录OUs中的列表:

aws organizations list-organizational-units-for-parent --parent-id r-examplerootid111

输出显示指定的根包含两个,OUs并显示每个根的详细信息:

{ "OrganizationalUnits": [ { "Name": "AccountingDepartment", "Arn": "arn:aws:organizations::o-exampleorgid:ou/r-examplerootid111/ou-examplerootid111-exampleouid111" }, { "Name": "ProductionDepartment", "Arn": "arn:aws:organizations::o-exampleorgid:ou/r-examplerootid111/ou-examplerootid111-exampleouid222" } ] }

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