Inject authorizer context variable into a REST API Gateway proxy request

0

Is it possible to inject a context variable into a REST API Gateway proxy request?

Use case: I am storing an API key in a Secrets Manager.

I want a custom authorizer to read the secret, and return it in the context.

An API Gateway (REST flavour) proxies requests to the target API that needs to be authorized.

And the goal is through the request mapping to inject the API key returned from the authorizer into the header of the proxied request.

For example: x-api-key: $context.authorizer.apiKey

profile picture
m0ltar
asked a year ago706 views
2 Answers
0

If you are using proxy integration then you can access the context data from the event payload requestContext block received in the integration. Suppose here the integration is a lambda proxy then from this lambda you can initiate another API request using the context data in the header form. If you have a HTTP integration then inside the Integration Request, you can map the http header x-api-key with value $context.authorizer.apiKey . This will invoke the backend integration using the required header.

AWS
SUPPORT ENGINEER
answered a year ago
-1

A Lambda Authorizer (custom authorizer) can only returns an IAM policy as an output. Lambda Authorizer cannot be used for your scenario. https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html

AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions