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개 답변
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
지원 엔지니어
답변함 일 년 전
-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
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인