Passing data from lambda to request header

0

My output from my authorizer follows the format specified by AWS, as seen 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, context contains a few parameters, like company_id, that I would like to pass along to my Node endpoint.

If I was to use a Lambda endpoint, I understand that this is done with Mapping Template and something like this:

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

However, Body Mapping Template is only available under Integration Request if Lambda is selected as Integration type. Not if HTTP is selected.

In short, how do I pass company_id from my Lambda authorizer to request header so that I can access the information in django?

I added the following under

Integration Request

  • And under Integration Request / HTTP Headers:

  • Name: company_id

  • Mapped from: context.authorizer.company_id

  • Cashing: optional

Still not able to get company_id under header in django request

  • Able to pull this off, missed adding the authorizer in MethodRequest. After adding authorizer in MethodRequest was able to get desired result

2 個答案
0

It seems you are following this stack overflow question: https://stackoverflow.com/questions/45631758/how-to-pass-api-gateway-authorizer-context-to-a-http-integration

From the answer there did you also add the company_id header in the Method Request / HTTP Request Headers section?

profile picture
已回答 1 年前
  • Yes, I am following the stack overflow question. Have gone through further comments and documentation adding header in MethodRequest is not needed

0

Mapping templates are available with HTTP integration unless you also select HTTP Proxy. VTL is not super easy but you can start with the Method Request passthrough model and add the values you need.

已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南