AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或CreateOrganizationalUnit
一起使用 CLI
以下代码示例演示如何使用 CreateOrganizationalUnit
。
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Creates a new organizational unit in AWS Organizations. /// </summary> public class CreateOrganizationalUnit { /// <summary> /// Initializes an Organizations client object and then uses it to call /// the CreateOrganizationalUnit method. If the call succeeds, it /// displays information about the new organizational unit. /// </summary> public static async Task Main() { // Create the client object using the default account. IAmazonOrganizations client = new AmazonOrganizationsClient(); var orgUnitName = "ProductDevelopmentUnit"; var request = new CreateOrganizationalUnitRequest { Name = orgUnitName, ParentId = "r-0000", }; var response = await client.CreateOrganizationalUnitAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully created organizational unit: {orgUnitName}."); Console.WriteLine($"Organizational unit {orgUnitName} Details"); Console.WriteLine($"ARN: {response.OrganizationalUnit.Arn} Id: {response.OrganizationalUnit.Id}"); } else { Console.WriteLine("Could not create new organizational unit."); } } }
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 CreateOrganizationalUnit” 中的。
-
- CLI
-
- AWS CLI
-
在根 OU 或父 OU 中创建 OU
以下示例演示如何创建名为 AccountingOU 的 OU:
aws organizations create-organizational-unit --parent-id
r-examplerootid111
--nameAccountingOU
输出包括一个 organizationalUnit 对象,其中包含有关新 OU 的详细信息:
{ "OrganizationalUnit": { "Id": "ou-examplerootid111-exampleouid111", "Arn": "arn:aws:organizations::111111111111:ou/o-exampleorgid/ou-examplerootid111-exampleouid111", "Name": "AccountingOU" } }
-
有关API详细信息,请参阅 “CreateOrganizationalUnit AWS CLI
命令参考”。
-
CreateOrganization
CreatePolicy