Use CreateAccount with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use CreateAccount with an AWS SDK or CLI

The following code examples show how to use CreateAccount.

.NET
AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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}."); } }
  • For API details, see CreateAccount in AWS SDK for .NET API Reference.

CLI
AWS CLI

To create a member account that is automatically part of the organization

The following example shows how to create a member account in an organization. The member account is configured with the name Production Account and the email address of susan@example.com. Organizations automatically creates an IAM role using the default name of OrganizationAccountAccessRole because the roleName parameter is not specified. Also, the setting that allows IAM users or roles with sufficient permissions to access account billing data is set to the default value of ALLOW because the IamUserAccessToBilling parameter is not specified. Organizations automatically sends Susan a "Welcome to AWS" email:

aws organizations create-account --email susan@example.com --account-name "Production Account"

The output includes a request object that shows that the status is now IN_PROGRESS:

{ "CreateAccountStatus": { "State": "IN_PROGRESS", "Id": "car-examplecreateaccountrequestid111" } }

You can later query the current status of the request by providing the Id response value to the describe-create-account-status command as the value for the create-account-request-id parameter.

For more information, see Creating an AWS Account in Your Organization in the AWS Organizations Users Guide.

  • For API details, see CreateAccount in AWS CLI Command Reference.