Mapping multiple headers in an API GatewayV2 HTTP API to a single header for use in a custom Lambda Authorizer as Identity Source

0

I have an HTTP ApiGatewayV2 setup, with a single AWS_PROXY endpoint to a lambda (using HTTP, not REST!). There are 2 sources of incoming requests, one is a frontend we control, and one is a 3rd party api. Both send JWT tokens with the requests, but in different headers. I am using a custom authorizer to validate the JWT tokens, and determine the policies based on the claim. Since I am using an AWS_PROXY with a single route for all requests, I need a single authorizer lambda to handle both tokens/headers. I would like to be able to cache the authorization responses from the authorization lambda, so I want to use the IdentitySource. But since there are 2 different headers that can contain the JWT token, this doesn't work. Unfortunately the Identity source entries need to ALL be present for the lambda to be invoked. So I can't specify ["$request.header.Authorization", "$request.header.OtherHeader"]. So would there be a way to somehow map $request.header.OtherHeader to $request.header.Authorization before the authorization lambda gets invoked? Or is there another trick to achieve something similar? Cheers

Dolf
已提问 10 个月前260 查看次数
1 回答
0

Mapping happens after authorization, so you can't do what you want in API Gateway.

What you can do is put a CloudFront distribution in front of API gateway and use CloudFront Functions to set the common header.

profile pictureAWS
专家
Uri
已回答 10 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则