How to pass Gateway API authorizer context for HTTP integration

I have successfully completed the Lambda authorizer for my AWS API gateway, but I want to pass a few custom properties from it to the Node.js endpoint.

My output from my authorizer follows the format specified by AWS, as shown below.

{
  "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",
    ...
  }
}

In my case, it contextcontains several parameters, for example company_id, which I would like to pass to my Node endpoint.

If I used the Lambda endpoint, I understand that this is done using a mapping pattern and something like this:

{
  "company_id": "$context.authorizer.company_id"
}

However, the body template template is only available in the integration request if Lambda is selected as the integration type. If HTTP is not selected.

In short, how do I pass company_idfrom my Lambda authorizer to my Node API?

+4
2

@Michael-sqlbot , , - .

Lambda

, , , .

{
  "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
    ...
  }
}

" / HTTP-" , :

  • : company_id
  • :
  • :

" /HTTP-" :

  • : company_id
  • : context.authorizer.company_id
  • :
+6

lamda-proxy, event.requestContext.authorizer.context.

, company_id event.requestContext.authorizer.context.company_id.

0

Source: https://habr.com/ru/post/1683511/


All Articles