AWS EC2
Authorization Error
Encoded Failure Message
Cloud Computing
Troubleshooting

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.

Practice system design

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.

bash
1aws sts decode-authorization-message \
2  --encoded-message "ENCODED_STRING_FROM_ERROR" \
3  --query DecodedMessage \
4  --output text

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:

bash
1aws sts decode-authorization-message \
2  --encoded-message "ENCODED_STRING_FROM_ERROR" \
3  --query DecodedMessage \
4  --output text | jq

Example: Missing EC2 Permission

Suppose a role tries to terminate an instance:

bash
aws ec2 terminate-instances --instance-ids i-0123456789abcdef0

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:

bash
aws sts get-caller-identity

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:

  1. copy the encoded message from the error output
  2. run decode-authorization-message
  3. identify the denied action and resource
  4. determine whether the denial is implicit or explicit
  5. inspect IAM policy, permission boundary, and organization policy layers
  6. 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.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design