Sub topic 14
Debugging AccessDenied with the policy simulator and CloudTrail
This chapter assumes you know the evaluation rules from the earlier chapters. Those rules are default deny, explicit deny wins, and a request needs at least one allow. It also assumes you know how identity policies, resource policies, permission boundaries, session policies, and SCPs fit together. You also need to be comfortable with the AWS CLI and with reading JSON.
Start with the error message
An AccessDenied error is a decision from the evaluation logic, and many error messages tell you which part denied the request. Read the message before you open any tool.
Recent AWS services often return text like this:
User: arn:aws:iam::111122223333:user/dana is not authorized to perform: s3:GetObject
on resource: "arn:aws:s3:::example-reports-bucket/2026/summary.csv"
because no identity-based policy allows the s3:GetObject actionThe last phrase tells you the cause. The common endings map to the evaluation rules like this:
| Phrase in the message | What it means | Where to look |
|---|---|---|
| `because no identity-based policy allows the action` | Implicit deny: no allow in the principal's identity policies. | Identity policies on the user, its groups, or the role |
| `because no resource-based policy allows the action` | Implicit deny: this request needed a resource-policy allow, as in many cross-account cases. | The resource's policy (bucket policy, key policy, and so on) |
| `with an explicit deny in an identity-based policy` | A Deny statement in a policy attached to the principal. | Search identity policies for `"Effect": "Deny"` |
| `with an explicit deny in a resource-based policy` | A Deny statement on the resource. | The resource policy |
| `with an explicit deny in a service control policy` | An SCP denies the action, or an SCP does not allow it. | Organizations policies on the account and its parent OUs |
| `with an explicit deny in a permissions boundary` | The boundary excludes the action. | The permissions boundary on the user or role |
Not every service or error includes this detail. Older or less detailed errors only say "Access Denied" or "not authorized". Some services also hide the reason on purpose. S3, for example, can return AccessDenied for a missing object when you lack s3:ListBucket, so that it does not reveal which keys exist. In those cases, move on to the simulator and CloudTrail.
Work through a checklist
When the message does not settle it, check the layers in a fixed order. Each check matches one rule from the evaluation flow.
- Confirm the request. Check the principal, action, resource ARN, and region. A role you assumed is not the user who signed in, so run
aws sts get-caller-identityto see who you really are. - Look for an explicit deny. Check every policy type that can contain one: identity policies, the resource policy, the permission boundary, SCPs, and session policies. Check Deny statements with conditions especially closely.
- Check the guardrails. An SCP or a permission boundary must allow the action. Neither grants anything, so both are silent about what the principal is actually given.
- Find an allow. Same-account: an identity policy or a resource policy allows it. Cross-account: both the identity policy and the resource policy must allow it.
- Check conditions. An allow that is present but has a condition that does not match counts as no allow.
- Check session policies. For a role session or federated user that was given a session policy, the session policy must also allow the action.
Use the policy simulator
The IAM policy simulator evaluates policies against an action and resource that you choose, without sending a real request. It is available in the console and through the CLI. Here is the command from the topic examples:
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::111122223333:role/ReportWriter \
--action-names s3:GetObject s3:PutObject \
--resource-arns arn:aws:s3:::example-reports-bucket/2026/summary.csvThe full output is long. This version keeps the useful fields:
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::111122223333:role/ReportWriter \
--action-names s3:GetObject s3:PutObject \
--resource-arns arn:aws:s3:::example-reports-bucket/2026/summary.csv \
--query "EvaluationResults[].{Action:EvalActionName,Decision:EvalDecision,Matched:MatchedStatements[].SourcePolicyId,Boundary:PermissionsBoundaryDecisionDetail.AllowedByPermissionsBoundary,MissingContext:MissingContextValues}" \
--output jsonEvalDecision is one of three values that mirror the core rule:
allowed: at least one allow applies and nothing denies.implicitDeny: no statement allowed the action.explicitDeny: a Deny statement matched.MatchedStatementsnames the policy that contains it.
Two fields are easy to overlook. PermissionsBoundaryDecisionDetail shows whether the permissions boundary allowed the action, which separates "my identity policy is missing" from "the boundary cuts it off". MissingContextValues lists condition keys that the policy uses but you did not supply. You can supply them with --context-entries, for example:
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::111122223333:role/ReportWriter \
--action-names s3:GetObject \
--resource-arns arn:aws:s3:::example-reports-bucket/2026/summary.csv \
--context-entries ContextKeyName=aws:SecureTransport,ContextKeyValues=false,ContextKeyType=booleanWith the DenyInsecureTransport bucket policy in mind, a context of false is how you test whether the TLS deny would fire.
What the simulator does not tell you
The simulator is a model of evaluation, not a replay of your request.
- It uses the policies you give it or that are attached to the principal. If the real denial comes from a resource policy, a session policy, or a VPC endpoint policy that you did not include, the result can say
allowedwhile the real request fails. For principal simulation, you can pass a resource policy with--resource-policy. - Condition keys that depend on the live request, such as source IP, VPC endpoint ID, or MFA age, take the values you supply. If you supply wrong or missing values, you get wrong answers.
- It does not test whether the resource exists, whether the service has its own checks (for example a KMS key policy that must also allow the use), or whether the network path works.
Find the real denied call in CloudTrail
CloudTrail records API calls, including failed ones. A denied call has an errorCode such as AccessDenied or Client.UnauthorizedOperation, plus an errorMessage. The record also gives the exact userIdentity that made the call, which is often different from what you assumed. For a role session, look at userIdentity.sessionContext and the assumed-role ARN.
For management events (IAM, EC2, and most control-plane calls), you can search the last 90 days from the CLI:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=RunInstances \
--max-results 50 \
--query "Events[?contains(CloudTrailEvent, 'UnauthorizedOperation') || contains(CloudTrailEvent, 'AccessDenied')].CloudTrailEvent" \
--output textKeep these limits in mind:
lookup-eventscovers management events only. S3 object calls such asGetObjectare data events. They appear only if you enabled data event logging on a trail, and you then query them in the trail's S3 bucket, CloudWatch Logs, or CloudTrail Lake.- Some EC2 errors come back with an encoded authorization message. Decode it with
aws sts decode-authorization-message --encoded-message <message>. Your caller needs thests:DecodeAuthorizationMessagepermission. - Events can take several minutes to appear.
Use these CloudTrail fields to build a precise simulator test: userIdentity.arn, eventSource, eventName, requestParameters (for the resource), sourceIPAddress, and awsRegion.
A worked example
A role ReportWriter can upload objects, but PutObject returns AccessDenied.
aws sts get-caller-identityshows the assumed role isReportWriter, so the identity is right.- The error says
with an explicit deny in a resource-based policy. That points at the bucket policy. - The simulator reports
implicitDenyfors3:PutObjectwith no boundary problem. The identity policy is the first suspect, but the message already tells you the bucket policy is where the denial comes from. Passing the bucket policy with--resource-policyrevealsexplicitDeny. - The matched statement is
DenyInsecureTransport. CloudTrail shows the upload came from a tool using plain HTTP. - The fix is on the client: use HTTPS. Do not remove the Deny.
Here the error message and CloudTrail agreed, and the simulator only found the cause once it was given the resource policy.
Exercise
A role has an identity policy that allows s3:PutObject on a bucket and an empty permissions boundary that allows only s3:GetObject. The simulator returns implicitDeny for s3:PutObject. Which field in the simulator output tells you the boundary is the cause, and what must you change?
Show answer
PermissionsBoundaryDecisionDetail.AllowedByPermissionsBoundary is false for s3:PutObject. The identity policy already allows the action, so the boundary is cutting it off. Add s3:PutObject on that bucket's objects to the boundary policy, if the access is intended. Editing the identity policy would not help, because a boundary grants nothing and only limits.
Exercise
You search CloudTrail with lookup-events for a denied s3:GetObject call and find nothing. Name one likely reason and what you would do.
Show answer
GetObject is an S3 data event, and lookup-events returns only management events. Data event logging may also be off. Enable data events on a trail for the bucket, reproduce the request, and query the trail's logs (S3, CloudWatch Logs, or CloudTrail Lake).