EC2 says you are not authorized and gives an encoded message
You are not authorized to perform this operation. Encoded authorization failure message: ...Short answer
EC2 hides the exact reason in an encoded message. Decode it with aws sts decode-authorization-message. The result names the action, the resource and whether a statement denied it explicitly or nothing allowed it. Then add the missing allow, remove the deny, or satisfy the condition it lists.
Fix it fast
1Find out which cause you have
Copy the long string after 'Encoded authorization failure message:' and decode it. The calling identity needs permission for sts:DecodeAuthorizationMessage.
aws sts decode-authorization-message \ --encoded-message "PASTE_ENCODED_MESSAGE" \ --query DecodedMessage --output text2Match what you see, then jump to its fix
- 1
Decoded JSON shows "allowed":false and "explicitDeny":falseNothing allows the actionFix - 2
Decoded JSON shows "explicitDeny":true and a matchedStatements entry with "effect":"DENY"A statement denies it explicitlyFix - 3
The decoded context lists condition keys such as ec2:InstanceType or aws:Region and a statement uses one of themA condition in the policy does not match your requestFix - 4
The decode command itself returns an access denied errorYou are not allowed to decode the messageFix
- 1
What does the error look like?
You are not authorized to perform this operation. Encoded authorization failure message: ...An error occurred (UnauthorizedOperation) when calling the RunInstances operation
Cause 1 of 4
Nothing allows the action
1Check
The message states whether the request was denied for lack of an explicit allow. Note the action and resource it lists.
aws sts get-caller-identity2Fix
Attach an allow for exactly that action and resource to the identity named in the message's principal.
{
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": "arn:aws:ec2:us-west-2:123456789012:instance/*"
}3Verify
Repeat the call that failed.
aws ec2 run-instances --dry-run --image-id ami-0123456789abcdef0 --instance-type t3.microConfirmed by docs.aws.amazon.com
Cause 2 of 4
A statement denies it explicitly
1Check
An explicit deny beats any allow. The matched statement tells you which one applies, with its statement id.
aws sts decode-authorization-message --encoded-message "PASTE_ENCODED_MESSAGE" --query DecodedMessage --output text2Fix
Edit or remove that deny statement, or narrow it so it no longer covers this request.
# Find the policy with the statement id shown in matchedStatements, then edit it.3Verify
Repeat the dry run once the policy has changed.
aws ec2 run-instances --dry-run --image-id ami-0123456789abcdef0 --instance-type t3.microConfirmed by docs.aws.amazon.com
Cause 3 of 4
A condition in the policy does not match your request
1Check
The decoded message includes the condition key values of your request. Compare them with the Condition block of the policy that should have allowed it.
aws sts decode-authorization-message --encoded-message "PASTE_ENCODED_MESSAGE" --query DecodedMessage --output text2Fix
Change the request to use an allowed value, or extend the allowed values in the policy.
aws ec2 run-instances --instance-type t3.micro --image-id ami-0123456789abcdef03Verify
The call returns instance details instead of UnauthorizedOperation.
aws ec2 run-instances --dry-run --image-id ami-0123456789abcdef0 --instance-type t3.microConfirmed by docs.aws.amazon.com
Cause 4 of 4
You are not allowed to decode the message
1Check
Decoding needs the sts:DecodeAuthorizationMessage action, because the details can contain privileged information.
aws sts get-caller-identity2Fix
Ask an administrator to grant that action to your identity, or to run the decode for you.
{
"Effect": "Allow",
"Action": "sts:DecodeAuthorizationMessage",
"Resource": "*"
}3Verify
Run the decode command again.
aws sts decode-authorization-message --encoded-message "PASTE_ENCODED_MESSAGE"Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Use --dry-run on EC2 calls in CI to find permission gaps before the real run.
- Give support or admin roles sts:DecodeAuthorizationMessage so people can decode their own errors.
- Keep condition keys such as instance types and regions documented next to the policy.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
Related fixes
Servers
Status code 460 on an AWS Application Load Balancer
elb_status_code 460 in ALB access logs
A 460 is generated by the load balancer, not by your app.
3 causes, each with a fixServers
Application Load Balancer returns 504 for requests to EC2 instances
HTTPCode_ELB_504_Count
A 504 from an Application Load Balancer means it could not get an answer from a target in time.
4 causes, each with a fixServers
Apache has a certificate, but https:// does not open
No line with :443 in the output of ss -ltnp
HTTPS needs four things at once: mod_ssl loaded, Apache listening on 443, a virtual host on 443 with SSLEngine on, and a firewall that lets 443 in.
4 causes, each with a fixServers
aws emr --steps fails: Error parsing parameter, Expected '=', received 'EOF'
Error parsing parameter '--steps': Expected: '=', received: 'EOF' for input:
The AWS CLI tried to read your option as shorthand key=value pairs and ran out of text where it expected an equals sign.
3 causes, each with a fixServers
AWS CLI says you must specify a region
You must specify a region. You can also configure your region by running "aws configure".
The AWS CLI sends every request to one region and has none to use.
4 causes, each with a fixServers
docker login to Amazon ECR fails with: Cannot perform an interactive login from a non TTY device
Cannot perform an interactive login from a non TTY device
Docker asked for a password because none reached it, and a pipe or script has no keyboard to answer.
3 causes, each with a fix