AWS EC2 'You are not authorized to perform this operation. Encoded authorization failure message'
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
This EC2 error means AWS denied the API call and returned an encoded message that explains why. The important detail is that the visible error is only the summary; the encoded payload usually tells you which policy type blocked the action, whether the denial was explicit, and which condition failed.
What The Encoded Message Means
When an IAM user or role calls an AWS API without sufficient permissions, AWS may include an encoded authorization failure message. You cannot read it directly, because it is meant to be decoded with AWS tools.
Typical root causes include:
- the principal is missing the required action such as
ec2:RunInstances - a resource-level permission does not match the ARN being accessed
- a condition key such as region, VPC, tag, or MFA requirement failed
- an explicit deny from a service control policy, permission boundary, or session policy overrode an allow
So the real debugging workflow is not guessing. It is decoding the message and then tracing which policy layer blocked the call.
Decode It With AWS CLI
The standard tool is sts decode-authorization-message. You need permission for sts:DecodeAuthorizationMessage in order to use it.
The output is JSON. It often includes fields describing:
- the denied action
- the resource
- matched statements
- explicit deny versus implicit deny
- context values that affected evaluation
Pipe it through jq if you want cleaner formatting:
Example: Missing EC2 Permission
Suppose a role tries to terminate an instance:
If the role lacks ec2:TerminateInstances, the decoded message may show that the action was not allowed for that resource. In practice, that points you to one of these fixes:
- add the missing action to the IAM policy
- widen an overly specific resource ARN condition
- remove or adjust an explicit deny higher up the policy chain
The decoded message helps you stop guessing which of those is happening.
Check More Than One Policy Layer
A common mistake is to look only at the IAM identity policy attached to the role. AWS authorization can be affected by several layers at once:
- identity-based policies on the user or role
- resource policies
- permission boundaries
- service control policies in AWS Organizations
- session policies from assumed roles or federation
An explicit deny in any of those layers wins over an allow elsewhere. That is why a policy that looks correct at first glance may still fail.
Use Policy Simulation And Caller Identity
Once you decode the message, confirm which identity made the request:
That helps catch a surprisingly common issue: you are debugging the wrong role or the wrong profile.
You can then simulate policies in the IAM console or compare the denied action with the attached policies. For EC2 errors, pay close attention to resource scoping and conditions around tags, regions, and instance attributes.
A Typical Fix Workflow
A good order of operations is:
- copy the encoded message from the error output
- run
decode-authorization-message - identify the denied action and resource
- determine whether the denial is implicit or explicit
- inspect IAM policy, permission boundary, and organization policy layers
- retest with the same AWS profile or role
That process is much faster than changing policies blindly.
Common Pitfalls
- Forgetting that you also need permission for
sts:DecodeAuthorizationMessage. - Checking only the IAM policy attached to the role and ignoring service control policies or permission boundaries.
- Debugging with one AWS profile and testing with another.
- Assuming the problem is EC2-specific when the real issue is a condition on tags, region, or MFA state.
- Fixing an allow statement while an explicit deny still exists somewhere else.
Summary
- The visible EC2 authorization error is only the summary; the encoded message contains the useful details.
- Decode it with
aws sts decode-authorization-message. - Make sure the caller can use
sts:DecodeAuthorizationMessage. - Look across all relevant policy layers, not just the role's inline or attached policies.
- Confirm the active caller identity before concluding that a policy change failed.
Related reading
- AWS ECR GetAuthorizationToken
- AWS ECR PULL no basic auth credentials
- AWS ECR Repository - How to copy images from one account and push to another account
- aws ecr saying Cannot perform an interactive login from a non TTY device after copied cmd from Amazon Container Services
- AWS IAM - Can you use multiple wildcards in a value
- AWS IAM Role vs Group
- AWS ECS agent won't start
- AWS ECS error Task failed ELB health checks in Target group
System design interview problems on this topic
- Design Dropbox: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough
- Design Youtube or Netflix: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.