Guide · IAM Identity Center · Account Assignments

IAM Identity Center Account Assignments for MCP Servers — Assigning Access and Getting Credentials

An account assignment in IAM Identity Center connects a user or group to an AWS account via a permission set. Once assigned, the user can sign into the SSO portal and choose that account to get short-lived credentials — or your MCP server tooling can call GetRoleCredentials programmatically using an access token from the OIDC device authorization flow. This guide covers creating assignments via the SDK, the CLI SSO session profile configuration, batch provisioning across all org accounts, retrieving credentials in Node.js, and the CDK L1 constructs.

TL;DR

Use CreateAccountAssignmentCommand (from @aws-sdk/client-sso-admin) to assign a group to an account. Poll DescribeAccountAssignmentCreationStatusCommand for SUCCEEDED. Developers then run aws sso login with an sso-session profile and AWS SDKs pick up the cached credentials automatically. MCP servers call GetRoleCredentialsCommand (from @aws-sdk/client-sso) with an OIDC access token to get the same credentials programmatically.

Creating an account assignment

An assignment is a triple: (principal, permission set, AWS account). The principal is either a user ID or group ID from the identity store. For multi-account MCP server infrastructure, assign a group rather than individual users — group membership changes automatically update access without touching account assignments.

import {
  SSOAdminClient,
  ListInstancesCommand,
  CreateAccountAssignmentCommand,
  DescribeAccountAssignmentCreationStatusCommand,
} from "@aws-sdk/client-sso-admin";

const ssoAdmin = new SSOAdminClient({ region: "us-east-1" });

const { instances } = await ssoAdmin.send(new ListInstancesCommand({}));
const INSTANCE_ARN = instances![0].instanceArn!;

// Assign a group to the production MCP server account
const result = await ssoAdmin.send(new CreateAccountAssignmentCommand({
  InstanceArn:       INSTANCE_ARN,
  TargetId:          "123456789012",          // the AWS account ID
  TargetType:        "AWS_ACCOUNT",
  PermissionSetArn:  "arn:aws:sso:::permissionSet/ssoins-xxx/ps-yyy",
  PrincipalType:     "GROUP",                 // "GROUP" or "USER"
  PrincipalId:       "12345678-aaaa-bbbb-cccc-123456789012",  // group ID from identity store
}));

const requestId = result.AccountAssignmentCreationStatus?.RequestId!;
console.log("Assignment request ID:", requestId);

The operation is asynchronous. The IAM role in the target account is created (or the existing role's trust policy is updated) in the background. Poll for completion:

// Poll until SUCCEEDED or FAILED
async function waitForAssignment(requestId: string): Promise {
  while (true) {
    await new Promise(r => setTimeout(r, 3000));
    const status = await ssoAdmin.send(
      new DescribeAccountAssignmentCreationStatusCommand({
        InstanceArn:                         INSTANCE_ARN,
        AccountAssignmentCreationRequestId:  requestId,
      })
    );
    const state = status.AccountAssignmentCreationStatus?.Status;
    console.log("Status:", state);
    if (state === "SUCCEEDED") return;
    if (state === "FAILED") {
      throw new Error(`Assignment failed: ${status.AccountAssignmentCreationStatus?.FailureReason}`);
    }
  }
}

await waitForAssignment(requestId);

Listing existing assignments

import {
  ListAccountAssignmentsCommand,
  ListAccountAssignmentsForPrincipalCommand,
} from "@aws-sdk/client-sso-admin";

// Who has access to account 123456789012 via the MCPServerDeveloper permission set?
const byAccount = await ssoAdmin.send(new ListAccountAssignmentsCommand({
  InstanceArn:       INSTANCE_ARN,
  AccountId:         "123456789012",
  PermissionSetArn:  "arn:aws:sso:::permissionSet/ssoins-xxx/ps-yyy",
}));
for (const a of byAccount.AccountAssignments ?? []) {
  console.log(a.PrincipalType, a.PrincipalId, "→", a.AccountId);
}

// What can a specific group access across all accounts?
const byPrincipal = await ssoAdmin.send(new ListAccountAssignmentsForPrincipalCommand({
  InstanceArn:   INSTANCE_ARN,
  PrincipalId:   "12345678-aaaa-bbbb-cccc-123456789012",
  PrincipalType: "GROUP",
}));
for (const a of byPrincipal.AccountAssignments ?? []) {
  console.log(a.AccountId, a.PermissionSetArn);
}

Batch provisioning across all org accounts

When onboarding a new group that should have access to every account in the organization, combine the Organizations API (to list accounts) with CreateAccountAssignment:

import { OrganizationsClient, paginateListAccounts } from "@aws-sdk/client-organizations";

const orgs = new OrganizationsClient({ region: "us-east-1" });
const GROUP_ID     = "12345678-aaaa-bbbb-cccc-123456789012";
const PS_ARN       = "arn:aws:sso:::permissionSet/ssoins-xxx/ps-yyy";
const REQUEST_IDS: string[] = [];

// Collect all account IDs in the organization
for await (const page of paginateListAccounts({ client: orgs }, {})) {
  for (const account of page.Accounts ?? []) {
    if (account.Status !== "ACTIVE") continue;

    const assign = await ssoAdmin.send(new CreateAccountAssignmentCommand({
      InstanceArn:      INSTANCE_ARN,
      TargetId:         account.Id!,
      TargetType:       "AWS_ACCOUNT",
      PermissionSetArn: PS_ARN,
      PrincipalType:    "GROUP",
      PrincipalId:      GROUP_ID,
    }));

    if (assign.AccountAssignmentCreationStatus?.RequestId) {
      REQUEST_IDS.push(assign.AccountAssignmentCreationStatus.RequestId);
    }

    // Rate limit: IdC throttles at ~10 req/s for CreateAccountAssignment
    await new Promise(r => setTimeout(r, 150));
  }
}

console.log(`Submitted ${REQUEST_IDS.length} assignment requests`);

// Poll all requests in parallel
await Promise.all(REQUEST_IDS.map(waitForAssignment));

IdC throttles CreateAccountAssignment at roughly 10 requests per second. The 150ms delay between calls keeps you safely within the limit. For organizations with hundreds of accounts, spread the work across multiple invocations rather than a single long-running script.

Deleting an assignment

import { DeleteAccountAssignmentCommand } from "@aws-sdk/client-sso-admin";

const deletion = await ssoAdmin.send(new DeleteAccountAssignmentCommand({
  InstanceArn:       INSTANCE_ARN,
  TargetId:          "123456789012",
  TargetType:        "AWS_ACCOUNT",
  PermissionSetArn:  PS_ARN,
  PrincipalType:     "GROUP",
  PrincipalId:       GROUP_ID,
}));

// Also async — poll DescribeAccountAssignmentDeletionStatus
const delRequestId = deletion.AccountAssignmentDeletionStatus?.RequestId!;

Deletion removes the trust relationship but does not delete the IAM role in the target account immediately — the role name persists with no trust entries, and is cleaned up by IdC the next time the permission set is modified.

CLI SSO session profile configuration

AWS CLI v2 uses SSO sessions to manage IdC-issued credentials. Configure ~/.aws/config:

# ~/.aws/config

[sso-session my-org]
sso_start_url        = https://d-1234567890.awsapps.com/start
sso_region           = us-east-1
sso_registration_scopes = sso:account:access

[profile mcp-production]
sso_session          = my-org
sso_account_id       = 123456789012
sso_role_name        = MCPServerDeveloper
region               = us-east-1
output               = json

[profile mcp-staging]
sso_session          = my-org
sso_account_id       = 234567890123
sso_role_name        = MCPServerDeveloper
region               = us-east-1

Log in with:

aws sso login --sso-session my-org
# Opens browser → SSO portal → user authenticates → credentials cached
# Cache location: ~/.aws/sso/cache/{sha1(start_url)}.json

# Verify credentials work
aws sts get-caller-identity --profile mcp-production

After login, any AWS SDK instantiated with profile: "mcp-production" (or with AWS_PROFILE=mcp-production set in the environment) automatically reads the cached credentials and refreshes them before expiry. The session token is valid for the SessionDuration set on the permission set (e.g., 8 hours); after expiry, re-run aws sso login.

Getting credentials programmatically with GetRoleCredentials

When a developer or automated process has an IdC access token (from the OIDC device authorization flow — covered in the SSO OIDC guide), they can call GetRoleCredentials from @aws-sdk/client-sso to get STS credentials for any assigned account:

import { SSOClient, GetRoleCredentialsCommand, ListAccountsCommand, ListAccountRolesCommand } from "@aws-sdk/client-sso";

// SSOClient is a data-plane client — targets the SSO portal, not the admin API
const sso = new SSOClient({ region: "us-east-1" });

// ACCESS_TOKEN comes from the OIDC device authorization flow (see SSO OIDC guide)
const ACCESS_TOKEN = "aGVsbG8gd29ybGQ...";   // 8h lifetime

// List which accounts the token holder can access
const accounts = await sso.send(new ListAccountsCommand({
  accessToken: ACCESS_TOKEN,
}));
for (const acc of accounts.accountList ?? []) {
  console.log(acc.accountId, acc.accountName);
}

// List which roles (permission sets) are available in a specific account
const roles = await sso.send(new ListAccountRolesCommand({
  accessToken: ACCESS_TOKEN,
  accountId:   "123456789012",
}));
for (const role of roles.roleList ?? []) {
  console.log(role.roleName);  // e.g., "MCPServerDeveloper"
}

// Get temporary STS credentials for a specific account + role
const creds = await sso.send(new GetRoleCredentialsCommand({
  accessToken: ACCESS_TOKEN,
  accountId:   "123456789012",
  roleName:    "MCPServerDeveloper",
}));

console.log("Access key:", creds.roleCredentials?.accessKeyId);
console.log("Expires at:", creds.roleCredentials?.expiration);
// expiration is milliseconds since epoch — convert for use in STS credential object

Use these credentials with any AWS SDK client:

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";

const rc = creds.roleCredentials!;
const dynamo = new DynamoDBClient({
  region: "us-east-1",
  credentials: {
    accessKeyId:     rc.accessKeyId!,
    secretAccessKey: rc.secretAccessKey!,
    sessionToken:    rc.sessionToken!,
    expiration:      rc.expiration ? new Date(rc.expiration) : undefined,
  },
});
// dynamo is now scoped to account 123456789012 with MCPServerDeveloper permissions

CDK L1 constructs for account assignments

To manage account assignments as code, use the CDK L1 construct from aws-cdk-lib/aws-sso:

import { CfnAssignment } from "aws-cdk-lib/aws-sso";
import * as cdk from "aws-cdk-lib";

// In a CDK Stack deployed to the management account (or delegated admin)
new CfnAssignment(this, "MCPDevAssignment", {
  instanceArn:       "arn:aws:sso:::instance/ssoins-0a1b2c3d4e5f6a7b",
  targetId:          "123456789012",
  targetType:        "AWS_ACCOUNT",
  permissionSetArn:  "arn:aws:sso:::permissionSet/ssoins-xxx/ps-yyy",
  principalType:     "GROUP",
  principalId:       "12345678-aaaa-bbbb-cccc-123456789012",
});

For large organizations, generate CfnAssignment constructs programmatically by looping over accounts from an SSM parameter or JSON config file, rather than hardcoding each one. This approach also works with CDK Aspects to enforce that every account always has a break-glass assignment for the platform team's permission set.

Auditing assignments with CloudTrail

Every CreateAccountAssignment call and every credential vend via GetRoleCredentials appears in CloudTrail. For the GetRoleCredentials event, the userIdentity.userName field contains the IdC username (e.g., alice@example.com), making it easy to audit which human or service account accessed which AWS account. Query with Athena or CloudWatch Logs Insights:

-- CloudTrail Lake query to find all IdC credential vends in the last 7 days
SELECT
  userIdentity.userName,
  requestParameters.accountId,
  requestParameters.roleName,
  eventTime
FROM
  my_event_data_store
WHERE
  eventName = 'GetRoleCredentials'
  AND eventSource = 'sso.amazonaws.com'
  AND eventTime > CURRENT_TIMESTAMP - INTERVAL '7' DAY
ORDER BY eventTime DESC;

Compare with the cross-account secrets access patterns — IdC credentials can then be used to call Secrets Manager in the target account without any additional cross-account trust policy.