Sub topic 8
Assigning a group and a permission set to an account
This chapter assumes you know IAM roles and policies, the AWS Organizations hierarchy, and basic AWS CLI usage. It also assumes you already have a permission set and a group in your Identity Center directory. The previous chapters covered both.
What an assignment is
An account assignment links three things:
- A principal: a user or a group in the identity store.
- A permission set: the reusable bundle of policies, session duration, and relay state.
- A target: one AWS account.
Together they say "members of this principal get this level of access in this account." The assignment is the only object that connects a permission set to an account. A permission set that has no assignments does nothing, and a group with no assignments cannot sign in to any account.
Assignment properties that matter
Three properties shape how you design and script assignments.
Assignments are per account. The target type is AWS_ACCOUNT, and there is no target type for an OU. If you want a group to reach every account in an OU, you create one assignment per account. The "Assigning across many accounts and OUs" chapter covers this at scale. Here, a loop over list-accounts-for-parent is enough.
Assignments are per permission set. One group can hold several permission sets in the same account, for example ReadOnlyAuditor and BillingViewer. Each pairing is a separate assignment, and each produces its own role. A user in the group sees one entry per permission set in the AWS access portal.
Assignments are created asynchronously. create-account-assignment returns right away with a request ID and a status of IN_PROGRESS. Identity Center then provisions the permission set into the account in the background. A zero exit code from the CLI means the request was accepted. It does not mean the role exists yet.
Prefer groups as principals
The API accepts USER or GROUP as the principal type. Assign to groups unless you have a one-off reason not to. Group membership then controls access. Adding a person to the Auditors group grants every assignment the group holds, and removing them revokes those assignments. You never have to edit assignments when people join or leave. Per-user assignments are hard to review because the account's access list becomes a list of individuals. The "Designing groups and permission sets that scale" chapter builds on this.
Create an assignment with the CLI
Run these commands in the management account, or in a delegated administrator account for Identity Center. Assignments are made through the sso-admin API, and the identity store is queried through identitystore. The commands below look up the IDs they need, then create one assignment and wait for it to finish.
INSTANCE_ARN=$(aws sso-admin list-instances \
--query 'Instances[0].InstanceArn' --output text)
IDENTITY_STORE_ID=$(aws sso-admin list-instances \
--query 'Instances[0].IdentityStoreId' --output text)
PS_ARN=$(aws sso-admin list-permission-sets \
--instance-arn "$INSTANCE_ARN" --query 'PermissionSets' --output text | tr '\t' '\n' | while read -r arn; do
NAME=$(aws sso-admin describe-permission-set \
--instance-arn "$INSTANCE_ARN" --permission-set-arn "$arn" \
--query 'PermissionSet.Name' --output text)
[ "$NAME" = "ReadOnlyAuditor" ] && echo "$arn"
done)
GROUP_ID=$(aws identitystore get-group-id \
--identity-store-id "$IDENTITY_STORE_ID" \
--alternate-identifier '{"UniqueAttribute":{"AttributePath":"DisplayName","AttributeValue":"Auditors"}}' \
--query 'GroupId' --output text)
REQUEST_ID=$(aws sso-admin create-account-assignment \
--instance-arn "$INSTANCE_ARN" \
--target-id 111122223333 \
--target-type AWS_ACCOUNT \
--permission-set-arn "$PS_ARN" \
--principal-type GROUP \
--principal-id "$GROUP_ID" \
--query 'AccountAssignmentCreationStatus.RequestId' --output text)
aws sso-admin describe-account-assignment-creation-status \
--instance-arn "$INSTANCE_ARN" \
--account-assignment-creation-request-id "$REQUEST_ID" \
--query 'AccountAssignmentCreationStatus.Status' --output textThe last command prints IN_PROGRESS, SUCCEEDED, or FAILED. If it prints FAILED, the same status object has a FailureReason field. Query it with --query 'AccountAssignmentCreationStatus.FailureReason'.
Two details are easy to miss. The permission set is identified by ARN, not by name, so you need a lookup step like the one above or a stored ARN. The group is identified by its ID in the identity store, not by its display name. get-group-id converts one to the other.
Assign to every account in an OU
Because the target is a single account, a loop does the work for an OU. This version lists the active accounts directly under one OU. It does not include accounts in child OUs, so repeat the loop for each child OU you need.
for ACCOUNT_ID in $(aws organizations list-accounts-for-parent \
--parent-id ou-xxxx-xxxxxxxx \
--query 'Accounts[?Status==`ACTIVE`].Id' --output text); do
aws sso-admin create-account-assignment \
--instance-arn "$INSTANCE_ARN" \
--target-id "$ACCOUNT_ID" \
--target-type AWS_ACCOUNT \
--permission-set-arn "$PS_ARN" \
--principal-type GROUP \
--principal-id "$GROUP_ID"
doneThis loop fires requests in quick succession and does not check any of them. Identity Center works on a limited number of changes at once, so a busy loop can hit a ConflictException or throttling. A production script should wait for each request to leave IN_PROGRESS, or retry with a delay.
Check what exists
Use the list calls to see the current state from either direction.
# Who has this permission set in this account?
aws sso-admin list-account-assignments \
--instance-arn "$INSTANCE_ARN" \
--account-id 111122223333 \
--permission-set-arn "$PS_ARN"
# Which accounts does this group reach?
aws sso-admin list-account-assignments-for-principal \
--instance-arn "$INSTANCE_ARN" \
--principal-id "$GROUP_ID" \
--principal-type GROUPThe first call needs both an account and a permission set. The second starts from the principal and returns account and permission set pairs. Use it when you want to answer "what can this group do, and where?" Both calls return IDs and ARNs. They do not return names, so resolve them with describe-permission-set or the identity store when you need a readable report.
Remove an assignment
delete-account-assignment takes the same five identifying values as create-account-assignment: instance, target, target type, permission set, and principal. It is also asynchronous, and you check it with describe-account-assignment-deletion-status. When the last assignment for a permission set in an account is removed, Identity Center removes the corresponding role from that account. Sessions already issued from that role keep working until they expire, so the session duration sets the upper limit on how long access lingers.
Common errors
| Symptom | Likely cause |
|---|---|
| `AccessDeniedException` | You are running in a member account, or the caller lacks `sso:CreateAccountAssignment` and related permissions. |
| `ValidationException` | A wrong target ID, an ARN from a different instance, or a principal ID that does not exist in the identity store. |
| `ConflictException` | Another change is still running for the same permission set or account. Wait and retry. |
| Status `FAILED` | Read `FailureReason`. A common cause is a customer managed policy that does not exist by name in the target account. |
| Request succeeded but users see nothing | Group membership is not synchronized yet, or the user is in a different group than you assigned. |
Exercise
A teammate runs create-account-assignment for the Auditors group in 40 accounts and sees exit code 0 on every call. Two accounts later turn out to have no role for the permission set. What did they skip, and which two CLI calls would show the cause?
Show answer
The call only accepts the request. Provisioning runs asynchronously, so a zero exit code does not mean it succeeded. They should have checked each request with describe-account-assignment-creation-status, using the returned request ID, and read FailureReason for any FAILED status. To see which accounts actually hold the assignment, run list-account-assignments for each account and permission set, or list-account-assignments-for-principal for the group.