【问题标题】:Can't specify response header in serverless.yml apiGatewayServiceProxies无法在 serverless.yml apiGatewayServiceProxies 中指定响应标头
【发布时间】:2020-12-10 18:39:52
【问题描述】:

我正在尝试在无服务器上使用此插件:- serverless-apigateway-service-proxy,我想创建一个接受 x-www-form-urlencoded 请求并返回 xml 正文的 apiGatewayService 代理。我可以通过以下方式完成所有这些工作:

    - sqs:
        path: /testing-sqs
        method: post
        queueName: { "Fn::GetAtt": ["MySpecialQueue", "QueueName"] }
        request:
          template:
            application/x-www-form-urlencoded: ${file(VTL/request.vtl)}
        response:
          - statusCode: 200
            selectionPattern: '2\d{2}'
            responseTemplates:
              application/xml: |-
                #set($inputRoot = $input.path('$'))

但是,当我在 postman 或 API Gateway 上进行测试时,响应内容类型标头是 application/json。通过将集成响应方法模型设置为:application/xml => Empty,我可以在 API Gateway 中手动更改此设置。

https://i.stack.imgur.com/cU7kI.png

如何在我的 serverless.yml 中指定集成响应模型,而不必在 API Gateway 中手动执行?

【问题讨论】:

    标签: amazon-web-services yaml aws-api-gateway amazon-sqs serverless


    【解决方案1】:

    所以似乎没有办法通过我可以找到的 responseParameters 来实现它,但是我能够通过使用映射模板覆盖标头来使其工作:

              - statusCode: 200
                selectionPattern: '2\d{2}'
                responseTemplates:
                  application/xml: |-
                    #set($inputRoot = $input.path('$'))
                    #set($context.responseOverride.header.Content-Type = 'application/xml')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-26
      • 1970-01-01
      • 2018-05-13
      • 1970-01-01
      • 2020-01-26
      • 2015-07-16
      • 1970-01-01
      相关资源
      最近更新 更多