How to pass API Gateway authorizer context to a HTTP integration

If you're using lamda-proxy, you can access the context from your event.requestContext.authorizer.context.

So your company_id can be accessed using event.requestContext.authorizer.context.company_id.


Most of the credit goes out to @Michael-sqlbot in the comments to my question, but I'll put the complete answer here if someone else finds this question.

Authorizer Lambda

It has to return an object in this format, where context contains the parameters you want to forward to your endpoint, as specified in the question.

{
  "principalId": "yyyyyyyy",
  "policyDocument": {
    "Version": "2012-10-17",
    "Statement": [{
      "Action": "execute-api:Invoke",
      "Effect": "Allow|Deny",
      "Resource": "arn:aws:execute-api:<regionId>:<accountId>:<appId>/<stage>/<httpVerb>/[<resource>/<httpVerb>/[...]]"
    }]
  },
  "context": {
    "company_id": "123", <-- The part you want to forward
    ...
  }
}

Method Request

Under Method Request / HTTP Request Headers, add the context property you want to forward:

  • Name: company_id
  • Required: optional
  • Cashing: optional

Integration Request

And under Integration Request / HTTP Headers, add:

  • Name: company_id
  • Mapped from: context.authorizer.company_id
  • Cashing: optional