Return application/xml from Serverless AWS Golang GET request HTTP endpoint

Ahoi

I have created a very simple HTTP Get endpoint in Serverless with Golang on AWS. Everything works fine, as long as I stay in JSON territory.

I would like to return xml now, especially the body. I found many issues, StackOverflows and documentation, but nothing works when I am testing it locally.

The most simple try I did was:

api_request_get:
  handler: bin/request_get
  memorySize: 256
  events:
    - http:
        path: /request
        method: get
        integration: lambda
        response:
          template: $input.path('$.body')
          headers:
            Content-Type: "'application/xml'"

I tried what is documented here https://www.serverless.com/framework/docs/providers/aws/events/apigateway#custom-response-templates and many other things or formats how to do it but nothing changes the result at all.

If I invoke it locally with e.g.

serverless invoke local -f api_request_get -p .\test_get.json

it always returns just a full Json response, not even only body for example, but everything as if the template is not picked, no matter if like this, with a specific status code etc.

Any hint or pointing in the right direction is highly appreciated because I am probably just missing this small thing ^^

Thanks a lot in advance

1 Like