Frankster
Frankster

Reputation: 689

Passing custom data from AWS Lambda Authorizer

In short, I want to pass information from my custom Lambda Authorizer to the backend. I have an rest API GW with a proxy integrated lambda as backend. The return object form the custom authorizer looks like this the json below. In this case I want to pass var1 and var2 to the proxy lambda.

{
    "principalId": "ExecuteAPISid",
    "policyDocument": {
        "Version": "2012-10-17",
        "Statement": [{
            "Action": "execute-api:Invoke",
            "Effect": "Allow",
            "Resource": "*"
        }]
    },
    "context": {
        "var1": "hello_world",
        "var2": "hello_world2"
    }
}

I see that this question has been asked and answered previously, however the suggested solution, as mention for example here, refers to "header mappings" under Integration Request in the AWS API Gateway menu. For me however, I have no such options. Thus I have an idea of what I want to do but lack the ability to how to implement it.

Does anyone have an idea of how to implement these header mappings? Complete settings shown in image below.

Edit: After further digging it turns out that the issue relates to me using using a lambda-proxy integration. This answer highlights just that. However, that simply shifts my question to: why is my requestContext not containing the authorizer object.

API GW settings

Upvotes: 1

Views: 1316

Answers (1)

Frankster
Frankster

Reputation: 689

Turns out that when you are using proxy integration then the context object from the custom Authorizer Lambda is automatically passed through to the event as:

"requestContext": {
    "resourceId": "XXXX",
    "authorizer": {
        "var1": "hello_world1",
        "var2": "hello_world2",
        "principalId": "ExecuteAPIS",
        "integrationLatency": 780
    },

The problem was that I had forgotten to "deploy" my API GW.

Upvotes: 1

Related Questions