Roles vs resource-based policies
Two ways to give another account or service access, and why the difference matters.
What it is
There are two ways to let a principal in one account use a resource in another:
- Assume a role in the other account, and act with that role's permissions.
- Call the resource directly, when the resource has a resource-based policy (such as an S3 bucket policy) that allows the caller.
Both work. The difference is what happens to the caller's own permissions.
How it works
- Top: assume a role. A user in Account A assumes a role in Account B, then reaches the bucket with the role's permissions. While in the role, the user gives up their Account A permissions.
- Bottom: resource-based policy. The bucket in Account B has a bucket policy that allows Account A. The user calls the bucket directly and keeps their own permissions.
Why it matters
A user in Account A needs to scan a DynamoDB table in Account A and write the results to an S3 bucket in Account B.
- With a role, they'd lose access to the DynamoDB table in A the moment they assumed the role in B. They'd have to switch back and forth.
- With a bucket policy in B allowing them, they read from A and write to B in one go, with their own permissions.
So when one task touches both accounts, a resource-based policy is simpler, if the service supports one.
Which services have resource-based policies?
Many, including: S3 buckets, SNS topics, SQS queues, Lambda functions, KMS keys, API Gateway APIs, ECR repositories, Secrets Manager secrets and EventBridge event buses. Services without them, such as EC2 or most of RDS's management actions, need a role.
Example: EventBridge targets
When an EventBridge rule fires, it needs permission to act on its target. Which method it uses depends on the target:
- Targets with resource-based policies (Lambda, SNS, SQS, S3, API Gateway): the target's policy allows EventBridge. For a Lambda function, a statement in the function's policy lets
events.amazonaws.cominvoke it. - Targets without them (EC2 Auto Scaling, Systems Manager Run Command, ECS tasks): EventBridge assumes an IAM role that has the permission.
Compared side by side
Assuming a role
- The caller gives up its own permissions for the session.
- Works with any service.
- Access is granted in the role's trust and permissions policies.
- Across accounts, the caller needs permission to call
sts:AssumeRole.
A resource-based policy
- The caller keeps its own permissions.
- Works only with services that support resource-based policies.
- Access is granted in the policy on the resource.
- Across accounts, the caller's identity policy must also allow the action.
Exam tips
- "Read from a resource in account A and write to a resource in account B at the same time" → resource-based policy on the B resource.
- "Service doesn't support resource-based policies" (EC2, for example) → cross-account role.
- "Allow EventBridge to invoke a Lambda function" → Lambda resource-based policy. "…to run an ECS task" → IAM role for EventBridge.
Common traps
- "Assuming a role adds its permissions to mine." It replaces them for the session.
- "Every service has resource-based policies." Only some do. Check before choosing that option.
Check yourself
This topic needs two accounts to try for real, so instead of a lab:
Add a bucket policy on B's bucket that allows the admin's principal (or account A) to s3:PutObject, and make sure the admin's identity policy in A allows it too. They keep their own permissions and can read from A and write to B together.
A resource-based policy on the Lambda function that allows events.amazonaws.com (scoped to the rule's ARN). Lambda supports resource-based policies.
A cross-account role in B with EC2 permissions, trusted by account A. EC2 has no resource-based policies.