Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Security and hardening · Decision guide

API Gateway or a Lambda function URL rejects a Bearer token as a malformed AWS signature

Short answer

AWS returns not a valid key=value pair (missing equal-sign) in Authorization header when it reads your Bearer or JWT token as a Signature Version 4 header. Usually the API Gateway method uses AWS_IAM authorization, or a Lambda function URL has auth type AWS_IAM. Change the authorizer to one that accepts your token, or sign the request with SigV4.

  • Applies to Amazon API Gateway REST APIs, AWS Lambda function URLs, AWS CLI v2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

AWS returns not a valid key=value pair (missing equal-sign) in Authorization header when it reads your Bearer or JWT token as a Signature Version 4 header. A signed header is built from pairs such as Credential=, SignedHeaders= and Signature=, so a bare token has none of the equal signs AWS expects.

That happens only when the endpoint uses IAM authorization: an API Gateway method with AWS_IAM, or a Lambda function URL with auth type AWS_IAM. The fix depends on which of the two you are calling and who your callers are.

Find your case

  1. If you call an address with execute-api in itAn API Gateway method that uses AWS_IAM is reading your token as a signature.
  2. If you call an address ending in lambda-url.<region>.on.awsA function URL with auth type AWS_IAM wants a signed request.
  3. If the header really is a SigV4 signature and the error remainsSomething is rewriting the header on the way.

See how the method is protected

For an API Gateway REST API, read the authorization type of the method you call.

Authorization type of one method

aws apigateway get-method --rest-api-id <api-id> --resource-id <resource-id> --http-method GET --query authorizationType
ValueExpects in Authorization
AWS_IAMA SigV4 signature made with AWS credentials
COGNITO_USER_POOLSA token issued by your user pool
CUSTOMWhatever your Lambda authorizer accepts
NONENothing

An API Gateway method that uses AWS_IAM

With AWS_IAM, the caller must be an AWS principal and sign each request. API Gateway looks for the signature pairs in a Bearer value, finds none and returns the equal-sign error. Decide who your callers are.

  • Browser or mobile users with Cognito or your own tokens: set the method to a Cognito user pool authorizer or a Lambda (CUSTOM) authorizer, then deploy the API to the stage again.
  • AWS services or your own back-end code with IAM roles: keep AWS_IAM and sign requests with an AWS SDK or the AWS CLI instead of attaching a token.

A method change is not live until you deploy to the stage. Run get-method again afterwards; it should print COGNITO_USER_POOLS or CUSTOM.

A Lambda function URL with AWS_IAM

Lambda's invocation guide says that with AWS_IAM every request to a function URL must be signed with SigV4, and Lambda compares its own signature with yours. A token in the header is not a signature, so the call is refused before your function runs.

Read the URL's auth type

aws lambda get-function-url-config --function-name my-function --query AuthType
  • Callers can sign requests (an AWS SDK, or a tool such as Postman with AWS signature support): keep AWS_IAM.
  • Callers only have your application token: switch the URL to NONE, add the public resource-based policy statements, and validate the token inside the function.

Switching a function URL to NONE

NONE makes the URL public, so the function is the only gate. Validate the token on every call, and reject a missing or invalid one with a 401 from your own code.

Public function URL with its two policy statements

aws lambda update-function-url-config --function-name my-function --auth-type NONE
aws lambda add-permission --function-name my-function --statement-id UrlPolicyInvokeURL \
  --action lambda:InvokeFunctionUrl --principal "*" --function-url-auth-type NONE
aws lambda add-permission --function-name my-function --statement-id UrlPolicyInvokeFunction \
  --action lambda:InvokeFunction --principal "*" --invoked-via-function-url

The second statement limits lambda:InvokeFunction to calls made through the function URL, so the function cannot be invoked another way by anyone.

A real signature that is still refused

If the header is a genuine SigV4 signature and the message still appears, something between the client and AWS may be rewriting the Authorization header: a proxy, a gateway or a client library. The IAM troubleshooting guide suggests comparing a hash of the header on both ends.

In short

  • The error means IAM authorization met a token; it is not a problem with the token itself.
  • Pick the authorizer by caller: Cognito or Lambda for users, IAM and SigV4 for AWS principals.
  • Smoke-test each route after every deployment.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. 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.

Next step

Want a second pair of eyes on it?

Send me the error and what changed before it started. I reply within 24 hours.