IAM AccessDenied Decoded
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Operations and security
-
Phase 3: SQL Server on AWS
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Every AWS engineer sees “AccessDenied” pretty much daily, and it’s the error most often “fixed” by adding AdministratorAccess. Fixing an AWS access denied error properly means reading which layer the message names, decoding the details when they’re encoded, and testing the fix with a dry run or the policy simulator before anyone goes near production.
You’ll create a role that can launch only t3.micro instances, trigger an encoded denial and decode it, prove the fix with the simulator, and see an SCP denial from your sandbox account. After that come an explicit deny and a permissions boundary, the two layers people tend to forget.
| Time | You need | By the end you can |
|---|---|---|
| 60 minutes | Lessons 5 to 7 and 33 done (IAM policies, the saat-sandbox profile and its SCPs), signed in as saat-admin. Cost: nothing, because every launch is a dry run. | Read modern AccessDenied messages, decode EC2 authorization failures, use --dry-run and simulate-principal-policy, and fix identity policies, explicit denies, permissions boundaries and SCPs in the layer where the problem really is. |
What it is, in one line
An AWS access denied error means either no policy allowed the request or a policy explicitly denied it, in one of the layers AWS checks: identity policies, resource policies, permissions boundaries, session policies or SCPs.
In Simple Words
The office building with many locks
To get to a meeting room you go through the building gate (the company’s rules for everyone), then your floor’s door (your department’s limit), and finally the room door (your own key card), and any one of them can stop you. A “No entry” sign on any door beats every key you’re carrying, and if your key card just doesn’t list that room, the door stays shut without any sign at all. A good guard tells you which door stopped you, and modern AWS error messages do that too, as long as you read them.
Engineer's View
How policy evaluation works
AWS evaluates every request the same way, and an explicit Deny in any policy that applies wins. If there isn’t one, every layer that applies has to allow the action: SCPs (and RCPs) for accounts in an organization, a permissions boundary if the user or role has one, session policies for assumed sessions, and either the identity policy or a resource policy that grants access. If nothing allows it, you get an implicit deny.
A lot of services now tell you which layer denied you, with wording like “no identity-based policy allows”, “explicit deny in an identity-based policy”, “no permissions boundary allows” or “explicit deny in a service control policy”. EC2 also gives an encoded authorization failure message, and aws sts decode-authorization-message turns it into JSON with allowed, explicitDeny, the matched statements and the full request context, such as the instance type.
--dry-run on EC2 checks permissions without creating anything. aws iam simulate-principal-policy evaluates a user’s or role’s policies, boundaries included, against actions, resources and context keys, and CloudTrail records denied calls with errorCode AccessDenied or UnauthorizedOperation.
How it works, step by step
Work through a denial in this order.
1Read the message
Find out who was denied (the ARN), the action, the resource and the layer named in the text, which on its own solves most cases.
2Decode and reproduce
Decode encoded messages so you can see the request context, and reproduce the problem safely with --dry-run or the simulator instead of trying the real action over and over.
3Fix the right layer, narrowly
Add the one missing action, resource or condition in the layer that denied it, and test again before you hand it back.
4Map the message to the layer
The wording tells you who owns the fix:
Never answer AccessDenied with AdministratorAccess, because it hides the real cause and leaves you with a bigger problem than the one you started with.
✅ Checkpoint: You can list the layers AWS evaluates, explain why an explicit deny wins, and say what each AccessDenied wording points to.
Hands-on lab: decode and fix four kinds of denial
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
Sign in and set names:
cd C:\aws-lab
aws login --profile saat-admin
$env:AWS_PROFILE = 'saat-admin'
$v = Get-Content C:\aws-lab\saat-vpc.json | ConvertFrom-Json
$acct = aws sts get-caller-identity --query Account --output text
$ami = aws ssm get-parameter --name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 --query Parameter.Value --output text1Create a role that may launch only t3.micro
Paste this whole block:
@{ Version = '2012-10-17'; Statement = @(@{ Effect = 'Allow'; Principal = @{ AWS = "arn:aws:iam::$($acct):root" }; Action = 'sts:AssumeRole' }) } | ConvertTo-Json -Depth 5 | Set-Content ops-trust.json
@{ Version = '2012-10-17'; Statement = @(
@{ Sid = 'RunMicroOnly'; Effect = 'Allow'; Action = 'ec2:RunInstances'; Resource = "arn:aws:ec2:ap-south-1:$($acct):instance/*"; Condition = @{ StringEquals = @{ 'ec2:InstanceType' = 't3.micro' } } },
@{ Sid = 'RunOtherResources'; Effect = 'Allow'; Action = 'ec2:RunInstances'; Resource = @('arn:aws:ec2:ap-south-1::image/*', "arn:aws:ec2:ap-south-1:$($acct):subnet/*", "arn:aws:ec2:ap-south-1:$($acct):network-interface/*", "arn:aws:ec2:ap-south-1:$($acct):security-group/*", "arn:aws:ec2:ap-south-1:$($acct):volume/*") },
@{ Sid = 'TagOnLaunch'; Effect = 'Allow'; Action = 'ec2:CreateTags'; Resource = '*'; Condition = @{ StringEquals = @{ 'ec2:CreateAction' = 'RunInstances' } } },
@{ Sid = 'Read'; Effect = 'Allow'; Action = 'ec2:Describe*'; Resource = '*' }) } | ConvertTo-Json -Depth 6 | Set-Content ops-policy.json
$roleArn = aws iam create-role --role-name saat-lab-ops --assume-role-policy-document file://ops-trust.json --query Role.Arn --output text
aws iam put-role-policy --role-name saat-lab-ops --policy-name run-micro --policy-document file://ops-policy.json
aws configure set profile.saat-ops.role_arn $roleArn
aws configure set profile.saat-ops.source_profile saat-admin
aws configure set profile.saat-ops.role_session_name ops-test
aws configure set profile.saat-ops.region ap-south-1
Start-Sleep 15
function Get-Decoded([string]$ErrText) {
$enc = [regex]::Match($ErrText, 'Encoded authorization failure message: (\S+)').Groups[1].Value
aws sts decode-authorization-message --encoded-message $enc --query DecodedMessage --output text | ConvertFrom-Json
}
function Test-Launch([string]$Type, [switch]$Tag) {
$tagArgs = if ($Tag) { @('--tag-specifications', 'ResourceType=instance,Tags=[{Key=course,Value=saatvedha-aws}]') } else { @() }
aws ec2 run-instances --dry-run --image-id $ami --instance-type $Type --subnet-id $v.PrivateA @tagArgs --profile saat-ops 2>&1 | Out-String
}
Test-Launch t3.microYou should see this:
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set.“Would have succeeded” is how a dry run tells you it worked: the permissions are fine and nothing was created. Run one every time you change an EC2 policy.
2Trigger and decode an encoded denial
Ask for a bigger instance and then decode the message:
$err = Test-Launch t3.small
$err.Substring(0, [Math]::Min(330, $err.Length))
$dec = Get-Decoded $err
$dec.allowed; $dec.explicitDeny; $dec.context.action
($dec.context.conditions.items | Where-Object { $_.key -eq 'ec2:InstanceType' }).values.items.valueYou should see something like this:
An error occurred (UnauthorizedOperation) when calling the RunInstances operation: You are not authorized to perform this operation. User: arn:aws:sts::111122223333:assumed-role/saat-lab-ops/ops-test is not authorized to perform: ec2:RunInstances on resource: arn:aws:ec2:ap-south-1:111122223333:instance/* because no identity-based policy allows the ec2:RunInstances action. Enco
False
False
ec2:RunInstances
t3.smallThe text already says “no identity-based policy allows”, and the decoded message fills in the context. explicitDeny is False, so it’s a missing allow rather than a deny, and the request asked for t3.small, which doesn’t match the RunMicroOnly condition. Decoding needs sts:DecodeAuthorizationMessage, which is why you run it as saat-admin.

3Prove the policy with the simulator
Paste this whole block:
foreach ($t in 't3.micro', 't3.small') {
$r = aws iam simulate-principal-policy --policy-source-arn $roleArn --action-names ec2:RunInstances --resource-arns "arn:aws:ec2:ap-south-1:$($acct):instance/*" --context-entries "ContextKeyName=ec2:InstanceType,ContextKeyValues=$t,ContextKeyType=string" --query "EvaluationResults[0].[EvalDecision,MatchedStatements[0].SourcePolicyId]" --output text
"$t $r"
}You should see something like this:
t3.micro allowed run-micro
t3.small implicitDeny NoneThe simulator agrees and names the policy that matched. In a change request, this output is your proof that a policy does what you claim before it’s deployed.
4See an SCP denial
If you built the sandbox account in Lesson 33, try a Region that its SCP blocks:
$scp = aws ec2 describe-vpcs --region us-east-1 --profile saat-sandbox 2>&1 | Out-String
$scp.Substring(0, [Math]::Min(300, $scp.Length))You should see something like this:
An error occurred (UnauthorizedOperation) when calling the DescribeVpcs operation: You are not authorized to perform this operation. User: arn:aws:sts::444455556666:assumed-role/OrganizationAccountAccessRole/... is not authorized to perform: ec2:DescribeVpcs with an explicit deny in a service control policyNothing in the sandbox account can override this, so if a fix is needed, it’s for whoever runs the organization.

✅ Checkpoint: The t3.micro dry run says “would have succeeded”, t3.small is denied with a decodable message showing t3.small, the simulator shows allowed vs implicitDeny, and the sandbox call names an SCP.
Break It, Then Fix It
These two denials confuse people because the identity policy looks fine.
1Break it: an explicit deny for missing tags
Add a company-style rule that says no launch without a course tag, and then try the launch that worked earlier:
@{ Version = '2012-10-17'; Statement = @(@{ Sid = 'RequireCourseTag'; Effect = 'Deny'; Action = 'ec2:RunInstances'; Resource = 'arn:aws:ec2:*:*:instance/*'; Condition = @{ Null = @{ 'aws:RequestTag/course' = 'true' } } }) } | ConvertTo-Json -Depth 6 | Set-Content ops-deny.json
aws iam put-role-policy --role-name saat-lab-ops --policy-name require-course-tag --policy-document file://ops-deny.json
Start-Sleep 15
$err = Test-Launch t3.micro
($err -split 'Encoded')[0]
(Get-Decoded $err).explicitDenyYou’ll get something like this:
An error occurred (UnauthorizedOperation) when calling the RunInstances operation: You are not authorized to perform this operation. User: arn:aws:sts::111122223333:assumed-role/saat-lab-ops/ops-test is not authorized to perform: ec2:RunInstances on resource: arn:aws:ec2:ap-south-1:111122223333:instance/* with an explicit deny in an identity-based policy.
TrueThe allow is still there, but a Deny matched, and a Deny always wins. Tag rules like this are common, and people try to “fix” them by asking for more permissions, which never helps. Fix: meet the condition by adding the tag:
Test-Launch t3.micro -TagYou should see this:
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set.2Break it: a permissions boundary
Give the role a boundary that allows only Describe calls, and then try the tagged launch:
'{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "ec2:Describe*", "Resource": "*" } ] }' | Set-Content boundary-v1.json
$bArn = aws iam create-policy --policy-name saat-ops-boundary --policy-document file://boundary-v1.json --query Policy.Arn --output text
aws iam put-role-permissions-boundary --role-name saat-lab-ops --permissions-boundary $bArn
Start-Sleep 15
$err = Test-Launch t3.micro -Tag
($err -split 'Encoded')[0]You’ll get something like this:
An error occurred (UnauthorizedOperation) when calling the RunInstances operation: You are not authorized to perform this operation. User: arn:aws:sts::111122223333:assumed-role/saat-lab-ops/ops-test is not authorized to perform: ec2:RunInstances on resource: arn:aws:ec2:ap-south-1:111122223333:instance/* because no permissions boundary allows the ec2:RunInstances action.
A boundary works as a ceiling, so the role only gets what both its policy and its boundary allow. Platform teams use boundaries to let developers create roles without escalating privileges, and then forget to widen them later. Fix: add a new boundary version with the actions the role needs:
'{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["ec2:Describe*", "ec2:RunInstances", "ec2:CreateTags"], "Resource": "*" } ] }' | Set-Content boundary-v2.json
aws iam create-policy-version --policy-arn $bArn --policy-document file://boundary-v2.json --set-as-default | Out-Null
Start-Sleep 15
Test-Launch t3.micro -TagYou should see this:
An error occurred (DryRunOperation) when calling the RunInstances operation: Request would have succeeded, but DryRun flag is set.Now clean up:
aws iam delete-role-permissions-boundary --role-name saat-lab-ops
$old = aws iam list-policy-versions --policy-arn $bArn --query 'Versions[?IsDefaultVersion==`false`].VersionId' --output text
foreach ($ver in ($old -split '\s+')) { if ($ver) { aws iam delete-policy-version --policy-arn $bArn --version-id $ver } }
aws iam delete-policy --policy-arn $bArn
aws iam delete-role-policy --role-name saat-lab-ops --policy-name run-micro
aws iam delete-role-policy --role-name saat-lab-ops --policy-name require-course-tag
aws iam delete-role --role-name saat-lab-ops
Remove-Item ops-trust.json, ops-policy.json, ops-deny.json, boundary-v1.json, boundary-v2.jsonYou should also delete the [profile saat-ops] section from your %USERPROFILE%\.aws\config file.
✅ Checkpoint: You fixed an explicit deny by meeting its tag condition and a boundary denial with a new boundary version. The role, its policies, the boundary policy and its versions have been removed.
This happened at work
The admin rights that didn’t help
At a fintech, a developer’s CI pipeline suddenly couldn’t launch build servers and kept failing with UnauthorizedOperation. The platform team was under pressure, so they attached AdministratorAccess to the pipeline role, and the error didn’t change one bit. When someone finally decoded the message, explicitDeny was true: a security policy denied RunInstances without a cost-center tag, and the pipeline’s launch template had lost its tags during a refactor, so no Allow was ever going to beat that Deny. They put the tags back and took AdministratorAccess off the same afternoon, and the team’s runbook now starts every AccessDenied ticket with “read the layer in the message, then decode”.
Common mistakes and troubleshooting
| Mistake | What happens | What to do |
|---|---|---|
| Attaching AdministratorAccess | Explicit denies still win; risk goes up | Fix the one missing permission |
| Ignoring the message text | Fixing the wrong layer | Read: identity, boundary, SCP, explicit deny |
| Not decoding EC2 messages | Guessing at conditions | sts decode-authorization-message |
| Testing with real launches | Costs and clutter | --dry-run and simulate-principal-policy |
| Forgetting boundaries | Role “has” permissions it can’t use | Check get-role PermissionsBoundary |
| Editing member accounts for SCP denials | Nothing changes | Org admins change SCPs |
Interview questions
Click a question to open it. Each one is phrased the way an interviewer would ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. Can you explain in simple words what an “explicit deny” means in AWS?
Why they ask this: They’re checking you understand the single most important rule of IAM policy evaluation.
How you might answer: It means a Deny statement matched the request, and a Deny always wins over any Allow in any policy. I usually compare it to a parent saying no, where it doesn’t matter how many other people said yes.
2. An EC2 call fails and gives you a long encoded authorization message. What do you do with it?
Why they ask this: They want to see you know how to get at the real reason behind an error instead of guessing.
How you might answer: I’d paste it into aws sts decode-authorization-message --encoded-message, and the output shows which action and resource were denied and why. My identity needs the sts:DecodeAuthorizationMessage permission to run it.
3. How can you check if you’re allowed to launch an EC2 instance without actually launching one?
Why they ask this: They want to see you test permissions safely, without creating resources or running up cost.
How you might answer: I’d add --dry-run to the command. DryRunOperation means I’m allowed and UnauthorizedOperation means I’m denied, and since nothing gets created either way, it’s safe to run any time.
2–5 years experience
4. A role has AdministratorAccess attached, but it still gets AccessDenied. How is that possible?
Why they ask this: They want to see you know every layer that can block a request, not only the identity policy.
How you might answer: Something above or around the identity policy is blocking it, like an explicit deny in an identity policy, a resource policy or an SCP, or else a permissions boundary or a session policy. AdministratorAccess only allows things, so it can’t beat any of those.
5. How would you explain a permissions boundary to a new team member?
Why they ask this: They want to know you understand how a boundary limits a role even when its policies allow more.
How you might answer: I’d say a boundary is a managed policy that sets the most an IAM user or role can ever do, without granting anything by itself. What the role can really do is the overlap between the boundary and its identity policies.
6. How does the IAM policy simulator help you when you’re debugging permissions?
Why they ask this: They want to see you test policies with tools before and after changes, instead of trial and error in production.
How you might answer: The simulator checks a principal’s policies, boundaries included, against the actions, resources and context keys I pick, and shows allowed, implicitDeny or explicitDeny. It also shows the matching statement, so I know which line to fix.
Senior level
7. You have 30 teams in AWS. How would you set up a least-privilege process that doesn’t slow everyone down?
Why they ask this: They want to see you balance security with speed, leaning on guardrails and automation instead of only manual reviews.
How you might answer: Access would come through permission sets in Identity Center, roles the teams create would need boundaries, and SCPs would sit on top as guardrails. IAM Access Analyzer would find unused access and help generate policies, and I’d add simulator checks in CI plus alerts on AccessDenied from CloudTrail.
8. Right after a deployment, AccessDenied errors spike. How would you investigate?
Why they ask this: They’re looking for a quick response based on evidence that fixes the problem without opening up too much access.
How you might answer: I’d query CloudTrail for errorCode AccessDenied or UnauthorizedOperation grouped by principal and action, and decode any encoded messages. Then I’d compare the policy versions in IaC from before and after the release and either roll back or make a narrow fix for just the missing permission.
Quick quiz
Q1. Which wins: an Allow or an explicit Deny?
- Allow
- Explicit Deny
- Whichever is newer
- Neither
Show answer
B — Deny always wins.
Q2. What does DryRunOperation mean?
- Denied
- Would have succeeded
- Instance launched
- Throttled
Show answer
B — Permissions are fine.
Q3. What decodes EC2 authorization messages?
- iam simulate
- sts decode-authorization-message
- kms decrypt
- base64
Show answer
B — It returns the evaluation JSON.
Q4. “No permissions boundary allows” means?
- Missing identity allow
- The boundary ceiling blocks it
- SCP deny
- Wrong Region
Show answer
B — Widen the boundary.
Q5. Who fixes an SCP denial?
- The developer
- The organization admins
- AWS Support
- Nobody
Show answer
B — SCPs are set at org level.
Quick recap
- Read the layer in the message: identity, boundary, SCP or explicit deny.
- Decode EC2 messages with sts decode-authorization-message.
- Test with
--dry-runand the policy simulator, not real actions. - Explicit denies win, boundaries are ceilings, and SCPs belong to the org admins.
- Keep fixes narrow, and never answer AccessDenied with AdministratorAccess.
Next lesson
Lesson 60: S3 403 and access problems → Next you’ll fix S3 403s caused by bucket policies, KMS keys, object ownership and Block Public Access.
Further reading: AWS access denied error
If you want to go further with AWS access denied error messages, read Troubleshoot access denied error messages and Policy evaluation logic. The full plan for this course is on the AWS Cloud Administration course page.
