Sub topic 5
Creating accounts and bringing in existing ones
This chapter assumes you have an organization with all features enabled, a management account, and at least one OU. It also assumes you are comfortable with IAM roles, trust policies and the AWS CLI. The previous chapters covered the hierarchy. This one covers how accounts get into it: creating new ones, inviting existing ones, and what you must do afterward.
Two ways to add an account
An account joins an organization in one of two ways.
| Path | Who starts it | Admin role created for you | Typical use |
|---|---|---|---|
| Create | Management account | Yes, `OrganizationAccountAccessRole` by default | New workloads, new environments |
| Invite | Management account, accepted by the other account | No | Existing accounts, acquisitions, accounts created by hand |
Prefer creating accounts when you can. A created account starts with the right trust relationship, the right email convention and a known state. An invited account has history you have to audit.
Creating a member account
The management account creates accounts with create-account. The request needs a unique email address and an account name.
aws organizations create-account \
--email [email protected] \
--account-name prod-app1 \
--role-name OrganizationAccountAccessRole \
--iam-user-access-to-billing DENYSeveral details matter here.
- The call is asynchronous. It returns a request ID that starts with
car-, not an account ID. - The email must not belong to any other AWS account, anywhere. Plus addressing such as
[email protected]is a common way to create many addresses that all deliver to one mailbox. A distribution list per account is better than a personal mailbox, because people leave. --role-nameis optional. Omitting it gives youOrganizationAccountAccessRole.--iam-user-access-to-billing DENYstops IAM users in the new account from viewing billing data. The default isALLOW.
Poll the request until it finishes:
aws organizations describe-create-account-status \
--create-account-request-id car-examplecreateaccountrequestid111The State field is IN_PROGRESS, SUCCEEDED or FAILED. On success the output includes the new AccountId. On failure, FailureReason gives a code such as EMAIL_ALREADY_EXISTS or ACCOUNT_LIMIT_EXCEEDED.
Placing the account
A new account lands directly under the root. Policies attached to the root apply to it immediately, but the policies you attached to your OUs do not. Move it into place right away:
aws organizations list-roots
aws organizations move-account \
--account-id 111122223333 \
--source-parent-id r-examplerootid111 \
--destination-parent-id ou-examplerootid111-exampleouid111Moving an account changes which SCPs apply to it at once. Moving it into an OU with stricter policies can break running workloads, so treat a move of a live account as a change that needs review.
What a new account looks like
A newly created account has no root user password. To get into it you have two options.
- Assume the administrative role from the management account. This is the normal route for setup.
- Use the "forgot password" flow on the account's root email address, then enable MFA on the root user and store the credentials safely.
The first route uses the role that Organizations created. It trusts the management account and carries AdministratorAccess.
aws sts assume-role \
--role-arn arn:aws:iam::111122223333:role/OrganizationAccountAccessRole \
--role-session-name admin-sessionThe call returns temporary credentials: an access key ID, a secret key and a session token. Export them as environment variables to run commands in the member account.
Treat OrganizationAccountAccessRole as a bootstrap path. Once IAM Identity Center is in place (a later chapter), people should not use this role day to day. Its trust policy lets any principal in the management account that has sts:AssumeRole permission use it, which makes it a high-value target. Keep the management account's own user population very small.
Inviting an existing account
An existing account joins through a handshake. A handshake is a request that one party sends and the other must accept.
From the management account:
aws organizations invite-account-to-organization \
--target Id=444455556666,Type=ACCOUNT \
--notes "Joining the Workloads OU"You can also use Type=EMAIL if you only know the root email address. From the invited account:
aws organizations list-handshakes-for-account
aws organizations accept-handshake \
--handshake-id h-examplehandshakeid111Invitations expire after 15 days. Cancel one with cancel-handshake if you sent it by mistake.
An invited account must satisfy a few conditions:
- It must not already be a member of another organization. It has to leave that one first with
leave-organization. - If the other organization is a different company's, the leaving account may need a payment method and complete contact details before AWS allows it to leave.
- If your organization has all features enabled, the invited account must accept that its permissions can now be restricted by SCPs.
Create the access role in an invited account
An invited account does not get OrganizationAccountAccessRole. If you want the same access path as created accounts, create the role yourself, from inside the invited account. Its trust policy names the management account:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::999988887777:root" },
"Action": "sts:AssumeRole"
}
]
}Replace 999988887777 with your management account ID. Attach AdministratorAccess or a narrower policy that matches your needs. Use the same role name everywhere, so scripts and Terraform providers do not need per-account logic.
Audit what you invited
An invited account is a risk until you have looked inside it. Before you move it into a production OU, check these things:
- IAM users with long-lived access keys, and who owns them
- The root user: its MFA status and whether it has access keys
- Existing resource policies and trust policies that grant access to outside accounts
- Whether the account is subject to a different company's billing or support contract
- Regions in use, in case your region-deny SCP would break them
A sensible pattern is to place the account in a quarantine or "Onboarding" OU with a restrictive SCP, fix findings, and then move it to its final OU.
Creating accounts with Terraform
If you manage the organization as code, accounts become reviewable resources:
resource "aws_organizations_account" "prod_app1" {
name = "prod-app1"
email = "[email protected]"
parent_id = aws_organizations_organizational_unit.workloads.id
role_name = "OrganizationAccountAccessRole"
lifecycle {
ignore_changes = [role_name]
}
}Two behaviors surprise people. First, role_name only has an effect when the account is created, so changing it later does not rename anything, and ignore_changes prevents a spurious diff. Second, destroying the resource does not close the account by default. Terraform tries to remove the account from the organization, which fails if the account lacks the standalone prerequisites such as a payment method. The provider has a close_on_deletion argument that closes the account instead. Treat that as a deliberate decision, because closing an account is not instantly reversible.
Common errors
EMAIL_ALREADY_EXISTS: the address is used by another AWS account. Use a different address or plus-address.ACCOUNT_LIMIT_EXCEEDED: raise the quota.AccessDeniedonassume-role: the caller lackssts:AssumeRole, or the role does not exist, as in an invited account.ConstraintViolationExceptiononleave-organization: the account has not completed its sign-up details.- Account stuck under the root: you forgot
move-account, so only root-level policies apply to it.
Exercise
You invite an existing account, 444455556666, and it accepts the handshake. You then run aws sts assume-role --role-arn arn:aws:iam::444455556666:role/OrganizationAccountAccessRole ... from the management account and get AccessDenied. Why, and what do you do?
Show answer
Invited accounts do not receive OrganizationAccountAccessRole, so the role does not exist. Sign in to the invited account and create the role there, with a trust policy that names the management account (arn:aws:iam::<management-account-id>:root) and an attached permissions policy. After that, the assume-role call works. Also place the account in an onboarding OU and audit it before moving it to a production OU.