WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

AWS · Expert · question 64 of 100

How do you set up and configure cross-account access using AWS IAM roles?

📕 Buy this interview preparation book: 100 AWS questions & answers — PDF + EPUB for $5

Setting up cross-account access using AWS IAM roles is a critical aspect of securing and managing resources in an AWS environment. It allows you to grant access to AWS resources in one account to users and applications in another account without having to share security credentials such as access keys or passwords.

Here are the steps to set up and configure cross-account access using AWS IAM roles:

Create an IAM Role in the destination account:

First, you need to create an IAM role in the destination account, which will define the permissions that are required to access resources in the account. You can create a role with a predefined policy that grants access to specific AWS services or create a custom policy that defines the permissions required for a specific set of resources.

Define a trust policy for the IAM Role:

After creating the IAM role, you need to define a trust policy that specifies which entities (users, roles, or accounts) are allowed to assume the role. The trust policy should include a statement that specifies the trusted account’s AWS account ID and the permissions that are allowed for the role.

Create an IAM User or Role in the source account:

Next, you need to create an IAM user or role in the source account that requires access to the resources in the destination account. The IAM user or role should have permissions to assume the IAM role created in the destination account.

Define an Assume Role policy for the IAM User or Role:

After creating the IAM user or role, you need to define an Assume Role policy that specifies the IAM role’s ARN in the destination account that the user or role is allowed to assume. The policy should also include a statement that allows the user or role to assume the role.

Access resources in the destination account:

Once the IAM role, trust policy, IAM user or role, and Assume Role policy are set up, the IAM user or role in the source account can assume the IAM role in the destination account and access the resources allowed by the permissions defined in the IAM role.

Here’s an example of how cross-account access can be set up between two AWS accounts using IAM roles:

Suppose you have two AWS accounts, Account A and Account B. Account A has an S3 bucket that needs to be accessed by an EC2 instance in Account B. To set up cross-account access, you would follow these steps:

In Account B, create an IAM Role with permissions to access the S3 bucket in Account A.

Define a trust policy for the IAM role in Account B that specifies the trusted account ID for Account A and the permissions required for the role.

In Account A, create an IAM user or role with permissions to assume the IAM role in Account B.

Define an Assume Role policy for the IAM user or role in Account A that specifies the IAM role ARN in Account B and allows the user or role to assume the role.

Launch an EC2 instance in Account B with an IAM role that includes the Assume Role policy.

Use the AWS SDK or CLI to assume the IAM role in Account B from the EC2 instance and access the S3 bucket in Account A.

In summary, setting up cross-account access using IAM roles is a powerful and secure way to manage access to AWS resources across multiple accounts. It allows you to grant granular permissions to users and applications without sharing security credentials, improving security and governance in your AWS environment.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic AWS interview — then scores it.
📞 Practice AWS — free 15 min
📕 Buy this interview preparation book: 100 AWS questions & answers — PDF + EPUB for $5

All 100 AWS questions · All topics