API Gateway 403 "User Is Not Authorized to Access This Resource": the Lambda Authorizer Cache Trap, Deny vs Unauthorized, "Explicit Deny in an Identity-Based Policy" and Resource Policies, Fixed

Logeshwaran
—

API Gateway's 403 "User is not authorized to access this resource" means the request got past authentication and was then refused by a policy. Which policy is in the wording. The plain message, with nothing after "resource", comes from a Lambda authorizer that returned a Deny, or an Allow that did not cover this method. The longer forms, "with an explicit deny in an identity-based policy" or "because no identity-based policy allows the execute-api:Invoke action", come from IAM authorization on a signed (SigV4) request, and "with an explicit deny in a resource-based policy" comes from the API's own resource policy. The fix for each is different, and the biggest time-waster of all is the authorizer cache: a Lambda authorizer's policy is cached for up to an hour and reused for every method of the API, so an authorizer that allows only the exact method it was first called for will return 403 on the second endpoint the same user hits, no matter what your code does when you test it fresh. Below: how to tell the three sources apart in under a minute, the cache trap and the policy shape that avoids it, the Deny-versus-Unauthorized rule that decides 403 or 401, the IAM and resource-policy cases, and what to put in the access log so the next one is obvious.

Jake's shop app got a proper login last month. Ethan wrote a Lambda authorizer that checks the customer's token and returns an Allow policy for the method being called, exactly as the AWS example does. Login worked, "my bookings" worked, and then every customer who opened "my bookings" and clicked "cancel" got {"message":"User is not authorized to access this resource"}. Ethan tested cancel on its own: fine. Tested it after "my bookings": 403, every time, for five minutes, then fine again. "So it works unless they did something else first," Jake said. That sentence is the authorizer cache in one line.

⚡ Quick Answer

• Plain message, works on one endpoint and not the next: authorizer cache. Return a policy covering the whole API (.../stage/*/*), or add the route to the cache key. Fix.

• Plain message, always: your authorizer returns Deny, or an Allow whose Resource ARN does not match the method. Fix.

• "...explicit deny in an identity-based policy" / "...no identity-based policy allows": IAM auth; fix the caller's IAM policy for execute-api:Invoke. Fix.

• "...explicit deny in a resource-based policy": the API's resource policy (IP, VPC, account). Fix.

Also: which 403 is this? · 403 vs 401 vs 500 · HTTP APIs · access logs · for IT admins.

New to API Gateway? Our plain-English API Gateway guide explains REST and HTTP APIs, stages and authorizers in about ten minutes. If your error is a 401 rather than a 403, start with our Cognito authorizer 401 guide; if it says Missing Authentication Token, that is a routing problem covered here.

🧭 NEW HERE? READ THESE FIRST

New to API Gateway, Lambda or IAM policies? These five pages give you the words this one uses:

📌 Bookmark this; the "which 403" table and the whole-API policy are the parts you will come back for.

Which 403 is this? Read the ending

API Gateway has several 403s, and the exact text sorts them. Compare your response body with this table before you change anything:

Response bodyWho refusedGo to
User is not authorized to access this resource (nothing after it)A Lambda authorizer's policy: Deny, or an Allow that does not cover this method; often a cached policy from another methodCache, policy
User: arn:aws:... is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:... because no identity-based policy allows the execute-api:Invoke actionIAM authorization (AWS_IAM): the signing identity has no Allow for this methodIAM
... with an explicit deny in an identity-based policyIAM authorization: a Deny statement on the caller's user or roleIAM
... with an explicit deny in a resource-based policyThe API's resource policy (source IP, VPC endpoint, account) or a VPC endpoint policyResource policy
... with an explicit deny in a service control policyAn AWS Organizations SCP above the caller's accountIAM
Missing Authentication TokenNo method at that path and verb (a routing error wearing a 403)Missing token guide
Forbidden on a custom domainBase path mapping, WAF, or a private API reached from outsideCustom domain 403

Everything with an ARN and the phrase execute-api:Invoke in it is IAM's standard access-denied wording, and the clause after "because" or "with" names the policy type that decided. The short, plain message is the one API Gateway writes for a Lambda authorizer's verdict. Our explicit deny guide covers the same endings for every other AWS service.

The cache trap: it works on the first endpoint and fails on the second

This is the cause behind most plain "not authorized" reports, and it only shows up in real use, never in a one-request test. A Lambda authorizer does not run on every request. When caching is on (it is on by default, with a TTL of 300 seconds, and can be set up to 3,600), API Gateway stores the policy your function returned, keyed by the identity source: the token header for a TOKEN authorizer, the configured headers, query strings and context variables for a REQUEST authorizer. For the rest of the TTL, any request from the same identity source is checked against the stored policy, whatever method it calls, and your function is not invoked at all.

Now look at what the AWS example authorizer returns: an Allow for event.methodArn, the ARN of the one method that triggered it. Jake's customer opened "my bookings" (GET /bookings); the authorizer ran and returned Allow for .../prod/GET/bookings, which was cached. Thirty seconds later the customer clicked cancel (POST /bookings/B-1042/cancel). The authorizer did not run; API Gateway evaluated the cached policy, found no statement covering POST /bookings/B-1042/cancel, and returned 403. Five minutes later the cache expired, the next call happened to be the cancel, and it worked.

You can prove it in a minute: call endpoint A, then endpoint B with the same token (403), wait past the TTL, call B first (works). Or set the TTL to 0 in the authorizer's settings and watch the 403 disappear; that is a diagnosis, not a fix, because every request now invokes the function.

There are three real fixes. Pick one:

  1. Return a policy for the whole API (the common choice). Build the Resource from the method ARN but replace the verb and path with wildcards, so one cached policy allows every method the caller may use:
# Python, inside the authorizer handler
# methodArn: arn:aws:execute-api:us-east-1:111122223333:a1b2c3d4e5/prod/GET/bookings
arn_prefix, api_part = event["methodArn"].split("/", 1)   # api_part = "prod/GET/bookings"
stage = api_part.split("/")[1]
api_wide = f"{arn_prefix}/{stage}/*/*"                     # arn:...:a1b2c3d4e5/prod/*/*

return {
    "principalId": user_id,
    "policyDocument": {
        "Version": "2012-10-17",
        "Statement": [{"Action": "execute-api:Invoke", "Effect": "Allow", "Resource": api_wide}],
    },
    "context": {"userId": user_id, "plan": plan},
}
  1. Return a policy with several statements when callers may use only some methods: Allow the methods this user's role permits, each as its own Resource (or a path wildcard such as .../prod/GET/bookings/*), and Deny the rest. The policy is still cached once, but it now answers correctly for every method.
  2. Put the method into the cache key. With a REQUEST authorizer, add context.httpMethod and context.path (REST) or $context.routeKey (HTTP API) to the identity sources. Each route then gets its own cached policy, at the price of one authorizer invocation per route per user per TTL.

A policy's Resource is limited to 512 characters, so very long paths or tokens in the ARN break it; keep tokens in headers, not in the URL. And remember the caching rule for REQUEST authorizers: when caching is on, every identity source must be present in the request, or API Gateway returns 401 without calling your function at all.

"So it remembered the first answer and kept giving it," Jake said. "It remembered the first question," said Ethan, "and the answer only covered that one."

The authorizer said Deny, or its Allow does not match

When the 403 happens on the very first call, caching is not the reason; the policy itself is. Three checks, in order:

  • Your code returned Deny. Read the authorizer's CloudWatch log for that request. If the function logged a denial (an expired token, a user without the right role), the 403 is correct and the fix is on the client or in the data. If your function cannot find the user or token, it should return Deny for a known user who is not allowed, and raise Unauthorized for an unknown or missing token (the next section explains why).
  • The Resource ARN does not match the method. The ARN must match the request's Region, account, API ID, stage, verb and path. A hard-coded ARN copied from a dev stage returns 403 in prod; an ARN built with the wrong case or a missing leading slash never matches. Log event.methodArn and the policy you return side by side once, and the mismatch is usually visible.
  • The policy shape is wrong. Version must be 2012-10-17, Action must be execute-api:Invoke, Effect is Allow or Deny with a capital letter, and principalId must be present. A malformed policy tends to surface as a 500 rather than a 403, but a syntactically valid policy with the wrong Effect or Resource gives a clean 403.
# see exactly what the authorizer was asked and what it answered
aws logs tail /aws/lambda/shop-authorizer --since 15m --format short

# test the authorizer the way API Gateway calls it (REST, TOKEN type)
aws apigateway test-invoke-authorizer --rest-api-id a1b2c3d4e5 --authorizer-id xyz123 \
  --headers Authorization="Bearer eyJ..." --query "[clientStatus, policy, log]"

test-invoke-authorizer returns the policy your function produced for that token and the authorizer's own log lines, without touching the cache. If the policy there is an Allow for the right ARN and real requests still get 403, you are back in the cache trap: a stale policy from an earlier call is being served. Redeploying the API after changing the cache key discards the cached policies; changing only the function code does not.

403 vs 401 vs 500: the three ways an authorizer can say no

Clients, and front-end code, treat these differently, so your authorizer should produce the right one on purpose:

Your functionClient getsMeaningCached?
Returns a policy with Effect: Deny403 "User is not authorized to access this resource"We know who you are; you may not do thisYes, for the TTL
Raises or calls back with the string Unauthorized401 "Unauthorized"We do not know who you are; sign in againNo
Raises anything else, times out, or returns an invalid policy500 "Internal server error" (REST may report "Invalid token")The authorizer itself brokeNo
Is never called because an identity source is missing (caching on)401The request lacks the header or query string the authorizer needsNo
Cannot be invoked (no permission for API Gateway)500Missing lambda:InvokeFunction for the authorizerNo

The practical rule: an expired or missing token should produce 401, so the app knows to refresh or re-login, and a valid token for a user who lacks permission should produce 403. Authorizers that return Deny for everything they do not like turn every expired session into a confusing "not authorized" and, worse, cache that Deny for five minutes, so the user's fresh login still fails until the TTL passes. Our API Gateway 500 guide covers the third row, including the add-permission the authorizer function needs.

HTTP APIs: isAuthorized and the per-route cache key

HTTP API Lambda authorizers have the same cache behavior with simpler plumbing. With payload format 2.0 and simple responses enabled, your function returns {"isAuthorized": true} or false; false gives the client a 403. The cache key is the identity sources (for example $request.header.Authorization), and by default the cached answer is used for every route of the API that shares the authorizer. A simple-response authorizer therefore allows or denies all routes for that identity for the TTL, which is fine when every signed-in user may call every route and wrong the moment you have admin-only routes.

# per-route caching: add the route key to the identity sources
aws apigatewayv2 update-authorizer --api-id a1b2c3d4e5 --authorizer-id def123 \
  --identity-source '$request.header.Authorization' '$context.routeKey' \
  --authorizer-result-ttl-in-seconds 300

# or return an IAM policy instead of a boolean, for per-route decisions in one cached answer
aws apigatewayv2 update-authorizer --api-id a1b2c3d4e5 --authorizer-id def123 --no-enable-simple-responses

Two HTTP-API specifics: if a configured identity source is missing from the request, the authorizer is not invoked and the client gets 401; and if API Gateway cannot invoke the function or the response is malformed, the client gets 500, with the reason in $context.authorizer.error in the access log.

IAM authorization: "no identity-based policy allows" and "explicit deny"

When a method uses AWS_IAM authorization, the caller signs the request with AWS credentials (SigV4), and API Gateway asks IAM whether that identity may execute-api:Invoke the method's ARN. The 403 then carries IAM's standard wording, and the ending tells you what to fix:

  • "because no identity-based policy allows the execute-api:Invoke action": the user or role has no Allow for this method. Attach one:
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": "execute-api:Invoke",
    "Resource": "arn:aws:execute-api:us-east-1:111122223333:a1b2c3d4e5/prod/*/*"
  }]
}
  • "with an explicit deny in an identity-based policy": a Deny on the caller wins over any Allow. Find the statement (often a shared "deny production" policy, or a Deny on execute-api:* meant for another API) and narrow it.
  • "with an explicit deny in a service control policy": the organization blocks it for the account or Region; only an Organizations administrator can change that.
  • The identity is not the one you think. The ARN after "User:" is the caller. A developer's laptop profile, a Lambda execution role, an EC2 instance role and a Cognito identity-pool role are all different identities, and the policy must be on the one in the message. aws sts get-caller-identity with the same credentials confirms it.

The Resource ARN format is arn:aws:execute-api:REGION:ACCOUNT:API-ID/STAGE/VERB/PATH, and a wildcard applies to everything after it: a1b2c3d4e5/* covers every stage and method; a1b2c3d4e5/prod/GET/* covers every GET in prod. Two traps: the stage is part of the ARN, so a policy written for dev gives 403 in prod; and the method must actually have AWS_IAM set as its authorization type, or IAM is never consulted and the method is public. For requests from a browser or a tool such as Postman, the request must be signed; an unsigned request to an IAM-protected method gets a 403 of its own (Missing Authentication Token), not this one. Our IAM policy JSON guide walks through the statement shape if it is new to you.

Resource policies: denied by IP, VPC or account

A REST API can carry its own resource policy, and "with an explicit deny in a resource-based policy" means that policy, or a VPC endpoint policy, refused the call. The common shapes:

  • An IP allow-list (aws:SourceIp) that does not include the office's new address, a VPN exit, or the NAT gateway your servers now use.
  • A private API that only accepts calls through a specific VPC endpoint (aws:SourceVpce); a call from the internet, from another VPC, or through the wrong endpoint is denied.
  • An account condition that lists the accounts allowed to call, which breaks the day a caller moves accounts.
# read the current resource policy
aws apigateway get-rest-api --rest-api-id a1b2c3d4e5 --query policy --output text | python -m json.tool

Resource policies are evaluated together with IAM and authorizer results, and a Deny in any of them ends the request. After editing a resource policy, deploy the API again; the running stage keeps the old policy until you do.

Put the reason in the access log

Every case on this page becomes a one-line diagnosis once the stage's access log records why the request was refused. For a REST API stage, use a JSON log format that includes:

{"requestId":"$context.requestId","ip":"$context.identity.sourceIp","method":"$context.httpMethod","path":"$context.path",
 "status":"$context.status","authorizerError":"$context.authorizer.error","principal":"$context.authorizer.principalId",
 "caller":"$context.identity.caller","userArn":"$context.identity.userArn","errorMessage":"$context.error.message",
 "responseType":"$context.error.responseType"}

responseType says ACCESS_DENIED for an authorizer or policy 403 and UNAUTHORIZED for a 401; principalId tells you a cached policy was used (the principal from the earlier call); userArn names the IAM identity in IAM-auth cases; and authorizer.error captures an authorizer that crashed. Enable it under the stage's Logs and tracing (REST) or Monitor > Logging (HTTP API), to a CloudWatch log group you create first.

For IT admins: an authorizer that does not surprise anyone

  • Return API-wide or role-wide policies, never a single method ARN, unless the method is part of the cache key.
  • 401 for unknown, 403 for known-but-forbidden, and never cache a Deny for a token that is merely expired.
  • Keep the TTL short while you build (60 seconds), then raise it once the policy shape is right; a long TTL hides every policy bug for an hour.
  • Redeploy after changing identity sources, so stale cached policies are discarded.
  • Log methodArn and the returned policy in the authorizer, and turn on stage access logs with $context.authorizer.error and $context.error.responseType.
  • Prefer REQUEST authorizers; multiple identity sources give you a precise cache key and let you include the route when you need per-route decisions.

Frequently asked questions

What does "User is not authorized to access this resource" mean in API Gateway?

A policy refused the request after authentication. The plain message is a Lambda authorizer's Deny or non-matching Allow; the longer IAM wording ("because no identity-based policy allows", "with an explicit deny") comes from IAM authorization or the API's resource policy.

Why does my API work on one endpoint and return 403 on the next?

Authorizer caching. The policy returned for the first method is cached by identity source and reused for every method for the TTL. Return a policy that covers the whole API or all permitted methods, or add the route to the identity sources.

How do I fix the Lambda authorizer cache 403?

Build the Resource as arn:aws:execute-api:REGION:ACCOUNT:API-ID/STAGE/*/* instead of event.methodArn, or return one Allow per permitted method, or add context.httpMethod and context.path (REST) or $context.routeKey (HTTP API) to the identity sources.

What is the default authorizer cache TTL?

300 seconds, and it can be set from 0 (off) to 3,600 seconds. The cache key is the identity source: the token header for TOKEN authorizers, the configured headers, query strings and context variables for REQUEST authorizers.

How do I clear the API Gateway authorizer cache?

Change the cache key parts (identity sources) and redeploy the API, which discards the cached policies, or set the TTL to 0 while you test. Changing only the function code does not clear cached policies.

Should my authorizer return Deny or raise Unauthorized?

Raise Unauthorized (401) for a missing, invalid or expired token so the client re-authenticates; return a Deny policy (403) for a valid identity that lacks permission. Denies are cached for the TTL; 401s are not.

What does "with an explicit deny in an identity-based policy" mean?

The method uses IAM authorization and a Deny statement attached to the calling user or role matches execute-api:Invoke on this method. Find and narrow that Deny; adding Allows cannot override it.

What does "because no identity-based policy allows the execute-api:Invoke action" mean?

IAM authorization found no Allow for the calling identity on the method's ARN. Attach a policy allowing execute-api:Invoke on arn:aws:execute-api:REGION:ACCOUNT:API-ID/STAGE/VERB/PATH, with wildcards as needed, to that user or role.

Why do I get this 403 in Postman?

Usually IAM authorization: the request is signed with credentials whose policy does not allow the method, or the policy names another stage. Check the ARN after "User:" and the Resource in the policy. An unsigned request gives Missing Authentication Token instead.

What does "with an explicit deny in a resource-based policy" mean?

The API's resource policy or a VPC endpoint policy denied the call, typically a source-IP allow-list, a private API reached from outside its VPC endpoint, or an account condition. Read it with get-rest-api and redeploy after changing it.

How do I see what my Lambda authorizer returned?

Run aws apigateway test-invoke-authorizer with the token header; it returns the policy and the function's log lines. For live traffic, log event.methodArn and the returned policy in the function, and add $context.authorizer.principalId to the stage access log.

Why does the authorizer return 403 for an admin route in an HTTP API?

With simple responses, the cached isAuthorized answer applies to all routes for that identity. Add $context.routeKey to the identity sources for per-route caching, or disable simple responses and return an IAM policy that lists the permitted routes.

Why 401 instead of calling my REQUEST authorizer?

With caching on, every configured identity source must be present in the request. If one is missing, null or empty, API Gateway returns 401 without invoking the function.

Can the Resource ARN in the authorizer policy be too long?

Yes. The Resource in the returned policy is limited to 512 characters, and a method ARN over 1,600 bytes returns 414. Keep tokens in headers rather than in the URL path.

Does changing the authorizer function clear cached policies?

No. Cached policies live until the TTL expires or until you change the cache key parts and redeploy the API.

How is this different from "Missing Authentication Token"?

Missing Authentication Token means no method exists for that path and verb, or an IAM-protected method was called unsigned. "User is not authorized" means a method was found and a policy refused the caller.

For readers preparing for an AWS certification

We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.

Exams that test this topic: Developer – Associate (DVA-C03 from December 1, 2026) • Security – Specialty (SCS-C03) • Solutions Architect – Associate (SAA-C03).

Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:

1. A Lambda authorizer allows the first endpoint a user calls but returns 403 on the next one. What is the cause?

Authorizer caching: the policy returned for the first method is cached for the identity and reused for other methods. Return a policy covering all permitted methods.

2. Which response should an authorizer give for an expired token: Deny or Unauthorized?

Unauthorized, which returns 401 so the client signs in again. Deny returns 403 and is cached.

3. Which authorizer type can use headers, query strings and context variables together?

A REQUEST type Lambda authorizer. A TOKEN authorizer reads a single header.

4. A partner's servers must call your API with AWS credentials. Which authorization fits?

IAM authorization with SigV4-signed requests, granting execute-api:Invoke on specific methods.

5. How do you limit a REST API to callers from your office IP range?

A resource policy that allows execute-api:Invoke only when aws:SourceIp matches, with a Deny for others.

6. Which log field shows why a request was refused?

$context.error.responseType in the access log, with $context.authorizer.error for authorizer failures.

Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.

Ethan changed one line in the authorizer: the Resource became /prod/*/*. Cancel worked after "my bookings," after "profile," after anything. He also split the exits, 401 for a dead token and Deny only for a real refusal, so an expired session no longer locks a customer out for five minutes after they log back in. "So the fix was to answer the whole question the first time," Jake said. "The first time is the only time it asks," said Ethan.

📌 If you keep one line from this page

Read the ending of the 403: plain means your Lambda authorizer's policy (usually a cached Allow for one method; return one for the whole API), "identity-based policy" means IAM on the caller, "resource-based policy" means the API's own policy.

Cache TTL 300 s, key = identity source · Deny = 403 cached, Unauthorized = 401 not cached · stage is part of the ARN.

Revision note. Written October 17, 2026. "Measure twice, cut once," the proverb says; an authorizer measures once and keeps the cut for five minutes.

Related