thepiranha
thepiranha

Reputation: 29

Can't specify response header in serverless.yml apiGatewayServiceProxies

I am trying to use this plugin on serverless: - serverless-apigateway-service-proxy and I want to make an apiGatewayService proxy that accepts a x-www-form-urlencoded request and returns an xml body. I am able to do all of that fine with the following:

    - 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('$'))

However, when I test in postman or on API Gateway, the response content type header is application/json. I am able to change this manually in API Gateway by setting the integration response method model as: application/xml => Empty.

https://i.sstatic.net/cU7kI.png

How can I specify the integration response model in my serverless.yml instead of having to do it manually in API Gateway?

Upvotes: 1

Views: 351

Answers (1)

thepiranha
thepiranha

Reputation: 29

so there doesn't seem to be a way to do it via the responseParameters that I can find however, I was able to make it work by overriding the header with a mapping template:

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

Upvotes: 1

Related Questions