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

2 Risposte
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
TECNICO DI SUPPORTO
con risposta un anno fa
-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
con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande