Skip to main content
This walkthrough shows how to allow an IAM user in one AWS account (Account B) to assume a role in another AWS account (Account A) to access S3 resources. The pattern demonstrated is a common cross-account access design: Account A creates a role with a trust policy that allows a principal from Account B to assume it; Account B grants that principal permission to call sts:AssumeRole. Example accounts and principals used in this guide:
  • Account A (target account): account ID 635573991785 — contains the role CrossAccountS3ReadRole
  • Account B (caller account): account ID 466456867028 — contains the IAM user Arnold2
  • In Account A there is also a local IAM user Anu (main account operator)
This example grants read-only S3 access to the assumed role. Replace account IDs, user names and role names with your real values where indicated. Table — quick reference

Overview: trust policy vs permission policy

  • Trust policy (attached to the role in Account A) controls who may assume the role.
  • Permission policy (attached to the role in Account A) controls what the role can do after being assumed.
  • The IAM user in Account B must also be granted sts:AssumeRole on the role ARN so they can initiate the assume operation.
For more on cross-account roles, see the AWS docs: IAM roles for cross-account access.

1) Create the cross-account role (in Account A)

  1. In Account A, open the AWS Console → IAM → Roles → Create role.
  2. When prompted for a trust policy, choose the option that lets you provide a custom trust policy (or paste JSON).
Example trust policy JSON (for Account A’s role). This allows the specific IAM user Arnold2 in Account B to assume the role. Replace the account ID and user name with your actual values:
  1. Attach the role’s permissions policy. For this demo we attach the managed policy AmazonS3ReadOnlyAccess so the role can list buckets and read objects.
  2. Give the role a descriptive name, for example CrossAccountS3ReadRole, then create it.
A screenshot of the AWS IAM console's "Create role" permissions page. It shows the Permissions policies panel with the AmazonS3ReadOnlyAccess policy selected.

2) Allow the IAM user in Account B to assume the role

In Account B, open the IAM console and select the IAM user Arnold2. Add an inline policy (or managed policy) that permits sts:AssumeRole on the role ARN in Account A. Example inline policy JSON for Arnold2 (attach in Account B):
Use the policy editor to paste this JSON and create the policy.
A screenshot of the AWS IAM console's "Create policy" page showing the Policy editor with Visual/JSON toggle, a "Select a service" section, and an "Add more permissions" button. The bottom-right shows "Cancel" and an orange "Next" button.
After creating and attaching this policy, Arnold2 has the required permission to call sts:AssumeRole on the CrossAccountS3ReadRole in Account A.

3) Switch role in the Console to assume the role

From the AWS Console while signed in as Arnold2 (Account B):
  1. Open the account / user menu and choose Switch Role.
  2. Enter the Account ID of Account A (635573991785) and the role name CrossAccountS3ReadRole.
  3. Optionally set a display label and color, then click Switch Role.
A screenshot of the AWS Identity and Access Management (IAM) Roles console. The roles list shows a highlighted role named "CrossAccountS3ReadRole" with the Create role button visible.
After the switch, the console header shows the active switched role, and the session will have the permissions of the role.
A screenshot of the Amazon Web Services "Switch Role" webpage. It shows an Account ID field and an IAM role color-label dropdown (None, Red, Orange, Yellow, Green, Blue) with Cancel and Switch Role buttons.

4) Verify S3 access with the assumed role

Once you’ve assumed CrossAccountS3ReadRole, open the S3 console. Because the role has AmazonS3ReadOnlyAccess, you can list buckets and view objects that the role is allowed to access. You will not be able to perform write operations (such as creating buckets) because the role only has read permissions.
A screenshot of the Amazon S3 web console showing the "General purpose buckets" view with a list of S3 bucket names, their AWS region (US East Ohio), and a prominent "Create bucket" button.
You can open buckets and inspect objects as permitted.
A screenshot of the Amazon S3 web console showing the "General purpose buckets" view with controls like Create bucket, Copy ARN, Empty, and Delete. The bucket list and columns (Name, AWS Region, Creation date) are visible.
If you attempt an action outside the role’s allowed actions (for example, creating a bucket), you will receive an access denied error:
A screenshot of the AWS S3 "Create bucket" page showing a red error box that reads "Failed to create bucket — To create a bucket, the s3:CreateBucket permission is required," with links to the IAM console. The top bar also shows the AWS account/role and region.
You can confirm the role’s attached policy in IAM to verify it only has AmazonS3ReadOnlyAccess:
A screenshot of the AWS IAM console displaying the "CrossAccountS3ReadRole" role's Permissions policies page. It shows the AmazonS3ReadOnlyAccess policy attached and the IAM navigation sidebar on the left.

Optional: Assume the role programmatically (AWS CLI example)

You can also assume the role using the AWS CLI or SDKs. Example CLI command: aws sts assume-role
—role-arn arn:aws:iam::635573991785:role/CrossAccountS3ReadRole
—role-session-name Arnold2Session
This returns temporary credentials (AccessKeyId, SecretAccessKey, SessionToken). You can export them into environment variables to run subsequent CLI commands under the assumed role. Example (bash):
See the AWS docs for programmatic assume-role details: AssumeRole API documentation.

Troubleshooting checklist

  • Ensure the trust policy on the role in Account A includes the correct principal ARN (user, role, or account).
  • Confirm Arnold2 in Account B has an IAM policy that allows sts:AssumeRole on the role ARN in Account A.
  • Verify the role in Account A has the correct permission policy attached (e.g., AmazonS3ReadOnlyAccess).
  • If using the Console switch-role feature, confirm you provided the exact Account ID and role name.
  • Check CloudTrail and IAM error messages for AccessDenied details if assumption fails.
Avoid granting broad trust (for example, Principal: "*") unless absolutely required. Always scope trust and permissions to the minimum set of principals and actions needed.

Summary

  • The trust policy on the role (Account A) defines who can assume it — in this example arn:aws:iam::466456867028:user/Arnold2.
  • The permission policy attached to the role defines what actions the role may perform after being assumed — here, AmazonS3ReadOnlyAccess.
  • The IAM user in Account B must have an IAM policy allowing sts:AssumeRole on the role ARN in Account A.
  • You can assume the role using the Console (Switch Role) or programmatically using AWS CLI/SDKs with STS.
Best practice: grant the least privilege necessary. Use specific principals in trust policies and attach only the required permissions to roles.
When finished in the console, use “Switch back” to return to your original IAM user session.

Watch Video