Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

EC2 says you are not authorized and gives an encoded message

ErrorYou 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.

  • Applies to AWS CLI 2, EC2 API 2016-11-15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 text
  2. 2Match what you see, then jump to its fix

    1. 1Decoded JSON shows "allowed":false and "explicitDeny":falseNothing allows the actionFix
    2. 2Decoded JSON shows "explicitDeny":true and a matchedStatements entry with "effect":"DENY"A statement denies it explicitlyFix
    3. 3The 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. 4The decode command itself returns an access denied errorYou are not allowed to decode the messageFix

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-identity

2Fix

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.micro

Confirmed by docs.aws.amazon.com

Did this fix it?

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 text

2Fix

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.micro

Confirmed by docs.aws.amazon.com

Did this fix it?

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 text

2Fix

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-0123456789abcdef0

3Verify

The call returns instance details instead of UnauthorizedOperation.

aws ec2 run-instances --dry-run --image-id ami-0123456789abcdef0 --instance-type t3.micro

Confirmed by docs.aws.amazon.com

Did this fix it?

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-identity

2Fix

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

Did this fix it?

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:

Related fixes

Servers

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 fix

Servers

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.