faraz
faraz

Reputation: 2733

how to send data from custom authorizer to api endpoint

Say, I have access to a certain value in custom authorizer, how do I pass it on to the api endpoint what I read till now, is that we could use context in the policy Generator to do that . something like this -

 authResponse.context = {
      "key": "this is the data sent from custom authorizer",
      "numKey": 1,
      "mysql":"sdf"
    };

but this code is in the policy generator and not in custom authorizer. so, how do I access the value that I got in custom authorizer and pass it on to the policy generator then?? my main aim is to send that value to the api endpoint.

Upvotes: 3

Views: 1151

Answers (1)

Daniel B.
Daniel B.

Reputation: 1680

You're correct that you need to add the information to authResponse.context. Once you do that, you can configure it as a URL Query String parameter, or Request Header, etc, via the "Integration Request" interface for your API Gateway method.

enter image description here

Now the value which was generated in your authorizer is available to the upstream endpoint of your API Gateway.

This solution is suggested (but not wholly spelled out) by the following documents:

"Amazon API Gateway API Request and Response Data Mapping Reference"

Map Method Request Data to Integration Request Parameters

Integration request parameters, in the form of path variables, query strings or headers, can be mapped from any defined method request parameters and the payload.

"API Gateway Mapping Template Reference"

$context.authorizer.property

The stringified value of the specified key-value pair of the context map returned from an API Gateway custom authorizer Lambda function. For example, if the authorizer returns the following context map:

"context" : { "key": "value", "numKey": 1, "boolKey": true } calling $context.authorizer.key returns the "value" string, calling $context.authorizer.numKey returns the "1" string, and calling $context.authorizer.boolKey returns the "true" string.

Upvotes: 2

Related Questions