[英]How to set integration endpoint dynamically based on request header in AWS API Gateway?
I would like to proxy the incoming requests to different endpoints based on a request header received in the request.我想根据请求中收到的请求标头将传入请求代理到不同的端点。
In AWS API gateway, I can set up different endpoints as separate stage variables but at integration >> Endpoint URL setting, I would like to pick the stage variable based on the value of request header value.在 AWS API 网关中,我可以将不同的端点设置为单独的阶段变量,但是在集成 >> 端点 URL 设置中,我想根据请求标头值的值来选择阶段变量。
For example:例如:
if header value is brand-id: abc then request should be proxied to abc.test.com如果标头值为brand-id:abc 那么请求应该被代理到abc.test.com
if header value is brand-id: pqr then request should be proxied to pqr.test.com如果标头值为brand-id: pqr 那么请求应该被代理到pqr.test.com
I'm expecting something like this in "Endpoint URL" value: http://${stageVariables.${method.request.header.brand-id}}/我期待“端点 URL”值中的类似内容: http://${stageVariables.${method.request.header.brand-id}}/
Any help to achieve this would be appreciated.任何帮助实现这一目标将不胜感激。
AFAIK this is not possible on the API Gateway level. AFAIK 这在 API 网关级别是不可能的。 Option is to do the mapping on the lambda integration level.
选项是在 lambda 集成级别上进行映射。
You can use Lambda Proxy Integration to achieve the similar behavior:您可以使用 Lambda 代理集成来实现类似的行为:
You can use python's adapter pattern, or string parameter formatting to save yourself from the clutter of if and else conditions.您可以使用 python 的适配器模式或字符串参数格式来避免 if 和 else 条件的混乱。 You can also consider calling Lambdas directly from your proxy Lambda with
RequestResponse
invoke, that may save yourself some time caused by the extra layer of API Gateway.您也可以考虑通过
RequestResponse
调用直接从您的代理 Lambda 调用 Lambda,这可能会为您节省一些时间,因为 API 网关的额外层。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.