

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 建立組織單位 (OU) AWS Organizations
<a name="create_ou"></a>

登入您的組織的管理帳戶時，您可以在組織的根建立一個 OU。OU 可以建立最多達五層的巢狀。若要建立您的第一個 OU，請完成以下步驟。

**重要**  
如果此組織是使用 管理 AWS Control Tower，請使用 AWS Control Tower 主控台或 APIs 建立您的 OUs。如果您在 Organizations 中建立 OU，則該 OU 不會註冊 AWS Control Tower。如需詳細資訊，請參閱*AWS Control Tower 使用者指南*中的[參照 AWS Control Tower外部資源](https://docs.aws.amazon.com/controltower/latest/userguide/external-resources.html#ungoverned-resources)。

**最低許可**  
若要在您的組織的根帳戶內建立 OU，您必須擁有以下許可：  
`organizations:DescribeOrganization` – 僅在使用 Organizations 主控台時才需要
`organizations:CreateOrganizationalUnit`

## AWS 管理主控台
<a name="create_ou_console"></a>

**建立組織單位 (OU)**

1. 登入 [AWS Organizations 主控台](https://console.aws.amazon.com/organizations/v2)。您必須以 IAM 使用者登入、擔任 IAM 角色，或是以組織管理帳戶中的根使用者 ([不建議](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#lock-away-credentials)) 身分登入。

1. 導覽至 **[AWS 帳戶](https://console.aws.amazon.com/organizations/v2/home/accounts)** 頁面。

   主控台會顯示根及其內容。第一次瀏覽根時，主控台會在該最上層檢視中顯示所有的 AWS 帳戶 。如果您之前建立了 OU，並將帳戶移至其中，主控台只會顯示最上層 OU 以及尚未移至 OU 的任何帳戶。

1. (選用) 如果您想要在現有 OU 內建立 OU，請透過選擇子 OU 的名稱 (而不是核取方塊)，或在樹狀檢視中選擇 OU 旁白的 ![Gray cloud icon with an arrow pointing downward, indicating download or cloud storage.](http://docs.aws.amazon.com/zh_tw/organizations/latest/userguide/images/expand-icon.png)，直至看到您所需的 OU，然後選擇其名稱，來[導覽至子 OU](navigate_tree.md)。

1. 當您在階層中選取正確的父 OU 時，請在 **Actions** (動作) 選單的 **Organizational Unit** (組織單位) 下方，選擇 **Create new** (建立新的)

1. 在 **Create organizational unit** (建立組織單位) 對話方塊中，輸入您要建立的 OU 名稱。

1. (選用) 選擇 **Add tag** (新增標籤)，然後輸入一個鍵和一個選用值，來新增一個或多個標籤。將值留空會將其設定為空白字串；而不是 `null`。您可以在 OU 中連接最多 50 個標籤。

1. 最後，選擇 **Create organizational unit** (建立組織單位)。

您的新 OU 會顯示在父系內。您現在可以[將帳戶移至此 OU](move_account_to_ou.md)，或將政策連接至此 OU。

## AWS CLI & AWS SDKs
<a name="create_ou_cli_sdk"></a>

**建立 OU**

下列程式碼範例示範如何使用 `CreateOrganizationalUnit`。

------
#### [ .NET ]

**適用於 .NET 的 SDK**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv3/Organizations#code-examples)中設定和執行。

```
    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 詳細資訊，請參閱《適用於 .NET 的 AWS SDK API 參考》**中的 [CreateOrganizationalUnit](https://docs.aws.amazon.com/goto/DotNetSDKV3/organizations-2016-11-28/CreateOrganizationalUnit)。

------
#### [ CLI ]

**AWS CLI**  
**在根或父 OU 中建立 OU**  
下列範例示範如何建立名為 AccountingOU 的 OU：  

```
aws organizations create-organizational-unit --parent-id {{r-examplerootid111}} --name {{AccountingOU}}
```
輸出包含 organizationalUnit 物件，其中包含新 OU 的詳細資訊：  

```
{
        "OrganizationalUnit": {
                "Id": "ou-examplerootid111-exampleouid111",
                "Arn": "arn:aws:organizations::111111111111:ou/o-exampleorgid/ou-examplerootid111-exampleouid111",
                "Name": "AccountingOU"
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateOrganizationalUnit](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/create-organizational-unit.html)。

------