Identity-based vs resource-based policies
Identity-based policies attach to a principal (user/group/role) and say what that principal can do. Resource-based policies attach to a resource (an S3 bucket policy, an SQS queue policy, a KMS key policy) and say who can access that resource — including principals from OTHER accounts, which is how cross-account access can work without assuming a role. When both exist within one account, the effective permission is the union of what each allows (still subject to any explicit Deny and, in an organization, SCP guardrails).
- Identity-based → on the principal; resource-based → on the resource
- Only resource-based policies have a Principal element and enable cross-account access
- Effective permission = union of allows, minus any explicit Deny
Exam tip: S3 bucket policies, SQS/SNS access policies and KMS key policies are the classic resource-based examples — the ones with a Principal.
Source: AWS docs — IAM User Guide
Policy evaluation logic & explicit deny
When a request is made, AWS collects all applicable policies — identity-based, resource-based, permission boundaries, session policies and (in an org) SCPs — and evaluates them together. The decision: if any explicit Deny matches, the request is denied; otherwise an Allow is required somewhere; otherwise the implicit default Deny applies. A permission boundary or SCP can only REDUCE permissions — being in an SCP/boundary does not grant anything by itself.
- Explicit Deny always wins, everywhere
- You need an Allow AND no Deny AND to be within any boundary/SCP
- Boundaries and SCPs cap permissions; they never grant them
Exam tip: If a scenario has an SCP or boundary plus an identity policy, the effective permission is the INTERSECTION (both must allow), minus any explicit Deny.
Source: AWS docs — IAM policy evaluation logic
Roles, STS and temporary credentials
IAM roles provide temporary, automatically-rotated credentials that a principal assumes via STS AssumeRole, avoiding long-lived access keys. EC2 instances receive a role through an instance profile; Lambda functions use an execution role; other services assume service roles to act on your behalf. A role has two policy sides: a trust policy (WHO may assume it) and a permissions policy (WHAT it can do once assumed). Preferring roles over static user keys is a core security best practice.
- Roles = temporary credentials from STS, assumed by services/users
- Two policies: trust policy (who can assume) + permissions policy (what it can do)
- Avoid long-lived user access keys for workloads
Exam tip: EC2 uses an INSTANCE PROFILE to receive a role; STS AssumeRole issues the temporary credentials. "Attach a role, never store keys" is the expected answer.
Source: AWS docs — AWS STS
IAM roles for AWS services
AWS services assume roles to act on your behalf: EC2 (instance profile) to call APIs from an app, Lambda (execution role) to write logs and reach other services, ECS tasks (task role), and many managed services. The service is named as the trusted principal in the role's trust policy (e.g. lambda.amazonaws.com). This keeps credentials out of your code and lets you scope exactly what each workload can touch.
- Service roles name the service (e.g. lambda.amazonaws.com) in the trust policy
- EC2 → instance profile; Lambda → execution role; ECS → task role
- Scope each workload's role to least privilege
Exam tip: A Lambda that writes to CloudWatch Logs and reads a DynamoDB table needs exactly those permissions in its execution role — nothing more.
Source: AWS docs — IAM User Guide
Comparison: IAM user vs role, identity vs resource policy
IAM user vs role: a user has long-term credentials for a persistent identity (a person or legacy app); a role has NO long-term credentials and issues temporary ones on assumption (services, cross-account, federation). Identity-based vs resource-based policy: identity policies live on the principal and say what it can do; resource policies live on the resource, name a Principal, and enable cross-account access. Permission boundary vs SCP: a boundary caps one IAM identity; an SCP caps whole accounts/OUs — both only restrict.
- User = long-term creds; Role = temporary creds (prefer roles for workloads/cross-account)
- Identity policy = on principal; Resource policy = on resource (has Principal, enables cross-account)
- Boundary = per-identity cap; SCP = per-account/OU cap; both only restrict
Source: AWS docs — IAM User Guide