首页 文章

AWS API Gateway:使用模拟集成进行重定向

提问于
浏览
3

如何在API网关中创建模拟集成以接收请求:

/products/{product}/bigFile.zip?platform={platform}&version={version}

并通过重定向回复:

http://xyz.cloudfront.net/{product}/{platform}/{version}.zip

我've tried changing the request and response mapping templates, but I'我不确定他们如何根据查询参数填充 Location 标头 .

更广泛的上下文(如果我提交了XY问题)是我正在使用AWS API Gateway构建API . 其中一个API endpoints 提供的大文件不符合API网关的10s响应时间限制,因此我想重定向到另一个CDN链接 .

1 回答

  • 2

    对于MOCK集成,请考虑将状态代码(例如{"statusCode":200})定义为后端的模拟状态代码的Integration Request模板 . 排除这方面,其他组件是相同的 . 你'll have to define a Method Response for the redirect 3xx status code and include any headers you want to send in the response. Then on the Integration Response page you can set the values for the headers as static values using single quotes. So that would be where you define the Location header with whatever the redirect URL is, like ' https://other.endpoint.com'

    编辑:使用Lambda函数echo的解决方法

    设置Lambda函数以回显有效负载 . 接下来将查询字符串映射到请求主体,如下所示:

    模板:

    {
      "q": $input.params('foo')
    }
    

    假设Lambda函数回显相同的有效负载,您可以在Integration Response中将头映射源设置为:

    integration.response.body.q
    

相关问题