Sub topic 18
Analyzing and troubleshooting access
This chapter assumes you know the policy evaluation rules (explicit deny, then allow, then implicit deny) and the guardrails that limit permissions: permissions boundaries and service control policies (SCPs). It shows how to find which of those layers blocked a request.
Start with who you are
Most "access denied" problems come from calling AWS as a different identity than you expected. Check first:
aws sts get-caller-identityThe output shows the account and the ARN. An assumed role appears as arn:aws:sts::ACCOUNT:assumed-role/ROLE/SESSION. Leftover AWS_ACCESS_KEY_ID variables from an earlier session override your profile, so check for them.
Work through the layers
Walk the layers in the order AWS evaluates them. Stop at the first layer that explains the denial.
Read the error message
Many AccessDenied messages name the cause, such as "with an explicit deny in a service control policy" or "no identity-based policy allows the action". Some services return an encoded message instead. If you have the sts:DecodeAuthorizationMessage permission, decode it:
aws sts decode-authorization-message \
--encoded-message <message from the error>The decoded result lists the matched statements and the context keys of the request.
Test with the policy simulator
The policy simulator evaluates a principal's policies against an action without making the call.
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::111122223333:user/dev-user \
--action-names s3:GetObject \
--resource-arns arn:aws:s3:::amzn-s3-demo-bucket/report.csvEach result has an EvalDecision of allowed, implicitDeny, or explicitDeny. The simulator does not evaluate every real-world factor, so you can test a condition by supplying --context-entries.
Confirm with CloudTrail
AWS CloudTrail records API calls. Search event history for the failed call and read errorCode, errorMessage, and userIdentity. This shows the exact principal, action, and time, which is useful when the problem is intermittent or comes from a service acting on your behalf.
Use Access Analyzer
IAM Access Analyzer reports resources shared outside your account or organization, such as buckets and roles with external trust. Use it to confirm that cross-account access is intended. It can also generate a policy from CloudTrail activity, which gives you a starting point for tighter permissions.
Common causes
| Symptom | Likely cause |
|---|---|
| Works in the console, fails in the CLI | Different identity or profile |
| `ListBucket` allowed, `GetObject` denied | Object actions need the `/*` ARN |
| Denied only without MFA | `BoolIfExists` deny matches missing MFA information |
| Cross-account call denied | Only one side allows it |
| Admin policy attached, still denied | SCP, boundary, or session policy |
Exercise
A user has an Allow for s3:GetObject on arn:aws:s3:::amzn-s3-demo-bucket/*. The simulator returns implicitDeny, and no policy contains a Deny. Name two layers you should check next.
Show answer
Check for a permissions boundary on the user (it must also allow s3:GetObject) and an SCP on the account or its organizational unit. A session policy or a mismatched resource ARN could also cause it. An implicit deny means nothing granted the action in every required layer.