ApiGateway HTTP Response Content-Type Mapping

Essentially, I have an endpoint that needs to return text/html content when the Accept header is set to text/html and application/json in a similar fashion.

What I have works… for the most part, except I cannot figure out how to change the Content-Type header to correspond to the Accept header in the request.

Here is a simplified example of what the .yml looks like:

    handler: src/handler.fooHandler
      - http:
          path: foo
          method: get
          integration: lambda
              Content-Type: "'text/html'"
               pattern: ''
                 application/json: '$input.json("$")'
                 text/html: ${file(velocity_templates/responseHTMLTemplate.vm)}

A little bit of context: moving some very ancient cgi-bin Python to APIGateway via SLS (even less important, we’ve rewritten it in TypeScript, et cetera). We intend for it to operate as a drop in before we migrate the user interface to a proper SPA. As such, the drop in needs to generate HTML hydrated with JSON that’s output from the handler. But to enable migration, we would like the same endpoint to just return the JSON for future use…

This does work. By enumerating the templates separately (under template) and using the correct function for the application/json, we do indeed get json back when the header Accept: application/json is present.

But the Content-Type in the response never changes. This is fine, for now, but ideally the Content-Type would match the payload.

I’ve poured over the docs and cannot figure out how to get this working. If I remove the Content-Type it no longer renders the HTML in the browser.

Is there some way of achieving this or do I have to tell the API consumers to ignore the Content-Type on the response and chock it up to a “quirk” of ApiGateway?