Writing IAM Policies and Tracing How AWS Evaluates Them
This lesson explains how IAM policies, JSON documents that allow or deny actions on resources, are written and evaluated. Knowing how AWS evaluates them is the key to troubleshooting almost every access problem.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the elements of a policy statement: Effect, Action, Resource, Principal and Condition.
- Trace how AWS evaluates a request, including default denies and explicit denies.
- Explain how condition operators and condition keys restrict when a statement applies.
- Apply least privilege and identify the tools that help investigate a denied request.
Policy structure
An IAM policy is a JSON document containing one or more statements. Each statement grants or denies a set of actions on a set of resources, optionally only under certain conditions. Effect is either Allow or Deny. Action lists API operations in the form service:Operation, and wildcards such as s3:Get* are allowed. Resource lists the ARNs the statement covers; for S3, the bucket ARN and the object ARN ending in /* are different resources, so listing a bucket and reading its objects need separate entries. Condition adds tests that must be true for the statement to apply. Principal names who receives access and appears only in resource-based policies. The following table summarises the elements.
| Element | Meaning |
|---|---|
Effect | Allow or Deny |
Action | The API actions covered, such as s3:GetObject |
Resource | The ARNs the statement applies to |
Condition | Optional rules that must be true, such as requiring MFA |
Principal | Who is granted access (resource-based policies only) |
Policies are attached in two places. An identity-based policy is attached to a user, group or role and says what that identity may do. A resource-based policy is attached to a resource, such as an S3 bucket policy, an SQS queue policy or a Lambda function policy, and says who may use that resource. Within one account, either kind can grant access. For access from another account, the caller's identity policy must allow the action and the resource policy must allow the caller's account or role. The following table summarises the two types.
| Policy type | Attached to |
|---|---|
| Identity-based | Users, groups and roles |
| Resource-based | Resources such as S3 buckets, SQS queues and Lambda functions; names the principal |
How AWS evaluates a request
AWS evaluates every request against all applicable policies in a fixed order. The evaluation proceeds as follows.
- Every request starts as denied by default.
- An explicit Deny in any applicable policy ends the evaluation: the request is denied.
- Otherwise, an explicit Allow grants access.
- Permissions boundaries and Organizations SCPs can only narrow the result; they never grant anything.
For cross-account access both sides must agree: the caller's identity policy and the resource-based policy (or, for a role, its trust policy) must each allow the request.
The following diagram shows the order in which AWS reaches a decision.

Trace the policy decision
Conditions
A condition makes a statement apply only when the request meets certain criteria. Each condition uses an operator, such as StringEquals, StringLike, IpAddress or Bool, to compare a condition key from the request context with one or more values. When a condition lists several keys, all must match; when a key lists several values, any one may match. Adding IfExists to an operator makes the condition true when the key is absent from the request.
Global condition keys are available for every service. They are commonly used in Deny statements that enforce rules across an account, for example denying any request where aws:SecureTransport is false, or any request outside the approved Regions. Tag keys support attribute-based access control (ABAC): a policy can allow access only when the principal's team tag equals the resource's team tag, so new resources need no policy changes. Service-specific keys restrict access within a resource, such as dynamodb:LeadingKeys, which limits a user to items whose partition key equals their own ID. Note that aws:SourceIp contains the public IP address of the caller, so it does not match requests that arrive through a VPC endpoint or are made by an AWS service on the caller's behalf.
The following table summarises several commonly used condition keys.
| Condition key | Use it to |
|---|---|
aws:SourceIp | Allow requests only from certain IP ranges |
aws:SecureTransport | Require HTTPS |
aws:MultiFactorAuthPresent | Require MFA |
aws:RequestedRegion | Restrict which Regions can be used |
aws:PrincipalTag, aws:ResourceTag | Attribute-based access control (ABAC) |
Service keys such as s3:prefix, dynamodb:LeadingKeys | Restrict access within a resource |
Example. The first statement allows all S3 actions; the second denies deletes without MFA. Without MFA the explicit deny wins. BoolIfExists also applies the deny when the MFA key is missing, as it is for long-term access keys.
{
"Version": "2012-10-17",
"Statement": [
{"Effect": "Allow", "Action": "s3:*", "Resource": ["arn:aws:s3:::team-data", "arn:aws:s3:::team-data/*"]},
{"Effect": "Deny", "Action": "s3:DeleteObject", "Resource": "arn:aws:s3:::team-data/*",
"Condition": {"BoolIfExists": {"aws:MultiFactorAuthPresent": "false"}}}
]
}Conditions and tools
Least privilege and troubleshooting
Permissions should be granted according to least privilege, and denials should be investigated systematically. The following list describes the recommended practices.
- Grant only the actions and resources each principal needs.
- IAM Access Analyzer and the IAM policy simulator show what a policy actually permits.
- Decode an encoded authorisation failure message with
aws sts decode-authorization-message.
Why is this request denied?
A developer's role has a policy allowing s3:* on arn:aws:s3:::reports. Calls to GetObject on reports/2026/q3.csv are denied. Working through the evaluation:
| Check | Result |
|---|---|
| Any explicit deny? | None found |
| Does an allow match the action? | Yes, s3:* includes GetObject |
| Does an allow match the resource? | No: arn:aws:s3:::reports is the bucket; objects are arn:aws:s3:::reports/* |
The policy needs both resources: the bucket ARN for bucket-level actions such as ListBucket, and the /* object ARN for object actions such as GetObject. This bucket-versus-object mistake is one of the most common causes of AccessDenied in S3, and the IAM policy simulator shows it immediately.
An identity-based policy allows s3:*, and the bucket policy denies s3:DeleteObject for the same user. Can the user delete objects?
Show answer
No. An explicit Deny in any applicable policy overrides every Allow.
Exam Tips
Remember for the exam
- An explicit Deny anywhere overrides every Allow.
- Cross-account access requires both the caller's identity policy and the resource policy to allow it.
- To allow an action only when MFA was used, add the
aws:MultiFactorAuthPresentcondition. - Decode an encoded authorisation failure message with
aws sts decode-authorization-message.