Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use CreateOrganizationalUnit
with an Amazon SDK or CLI
The following code examples show how to use CreateOrganizationalUnit
.
- .NET
-
- Amazon SDK for .NET
-
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.");
}
}
}
- CLI
-
- Amazon CLI
-
To create an OU in a root or parent OU
The following example shows how to create an OU that is named AccountingOU:
aws organizations create-organizational-unit --parent-id r-examplerootid111
--name AccountingOU
The output includes an organizationalUnit object with details about the new OU:
{
"OrganizationalUnit": {
"Id": "ou-examplerootid111-exampleouid111",
"Arn": "arn:aws:organizations::111111111111:ou/o-exampleorgid/ou-examplerootid111-exampleouid111",
"Name": "AccountingOU"
}
}
For a complete list of Amazon SDK developer guides and code examples, see
Using Amazon Organizations with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.