

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# `CreateAccount`与 AWS SDK 或 CLI 配合使用
<a name="organizations_example_organizations_CreateAccount_section"></a>

以下代码示例演示如何使用 `CreateAccount`。

------
#### [ .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 AWS Organizations account.
    /// </summary>
    public class CreateAccount
    {
        /// <summary>
        /// Initializes an Organizations client object and uses it to create
        /// the new account with the name specified in accountName.
        /// </summary>
        public static async Task Main()
        {
            IAmazonOrganizations client = new AmazonOrganizationsClient();
            var accountName = "ExampleAccount";
            var email = "someone@example.com";

            var request = new CreateAccountRequest
            {
                AccountName = accountName,
                Email = email,
            };

            var response = await client.CreateAccountAsync(request);
            var status = response.CreateAccountStatus;

            Console.WriteLine($"The staus of {status.AccountName} is {status.State}.");
        }
    }
```
+  有关 API 的详细信息，请参阅 *适用于 .NET 的 AWS SDK API 参考[CreateAccount](https://docs.aws.amazon.com/goto/DotNetSDKV3/organizations-2016-11-28/CreateAccount)*中的。

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

**AWS CLI**  
**创建自动属于组织的成员账户**  
以下示例演示如何创建组织的成员账户。为成员账户配置的名称为 Production Account，电子邮件地址为 susan@example.com。 OrganizationAccountAccessRole 由于未指定 roleName 参数，Organizations 会使用默认名称自动创建 IAM 角色。此外，由于未指定 IamUserAccessToBilling 参数，允许具有足够权限的 IAM 用户或角色访问账户账单数据的设置被设置为默认值 ALLOW。Organiations 会自动向 Susan 发送一封 “欢迎来到 AWS” 电子邮件：  

```
aws organizations create-account --email susan@example.com --account-name "Production Account"
```
输出包括一个请求对象，以显示状态目前为 `IN_PROGRESS`：  

```
{
        "CreateAccountStatus": {
                "State": "IN_PROGRESS",
                "Id": "car-examplecreateaccountrequestid111"
        }
}
```
稍后，您可以通过向 describe-create-account-status命令提供 Id 响应值作为 create-account-request-id参数值来查询请求的当前状态。  
有关更多信息，请参阅《Organi AWS zations *用户指南》中的在AWS 组织*中创建帐户。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CreateAccount](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/create-account.html)*中的。

------