Q: How to kill the default request mapping templates from API Gateway?

Is there any way to delete the default request mapping templates that are generated by serverless by default in API Gateway? My lambda function wants the passthrough json from an application/json-type request, not the re-mapped version.

Alternatively, is there a way to create a mapping that is similar to a passthrough?

Either solution would work for me.

My lambda functions work great if I go in manually after a ‘serverless deploy’ and delete the request mapping templates, but I can’t for the life of me figure out a way to stop those templates from being created in the first place.

Hey @scumola, what integration type are you using for your function?

If possible, could you post the whole functions block for your serverless.yml ? I’ll experiment and see if I can figure out a workaround :slight_smile:

Thanks @alexdebrie1

    handler: investor/create/index.handler
        - investor/create/**
      - http:
          path: investor
          method: post
          cors: true
          integration: lambda

It’s these that I want to get rid of:

@scumola I dug around on this and have an update. There’s no way to not send up any templates at all, as the Framework automatically sends up application/json and application-x-www-form-urlencoded templates. See here.

You can overwrite those templates, so it looks like you’d have to go with your second option, which is to use a mapping that’s similar to a passthrough. I can’t find docs on what that looks like – can you send me an event after a passthrough?

This fixes it.

diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/integration.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/integration.js
index d9e76d3fde..e3b327df57 100644
--- a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/integration.js
+++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/integration.js
@@ -171,12 +171,12 @@ module.exports = {
     const integrationRequestTemplates = {};
     // Only set defaults for AWS (lambda) integration
-    if (useDefaults) {
-      _.assign(integrationRequestTemplates, {
-        'application/json': this.DEFAULT_JSON_REQUEST_TEMPLATE,
-        'application/x-www-form-urlencoded': this.DEFAULT_FORM_URL_ENCODED_REQUEST_TEMPLATE,
-      });
-    }
+//    if (useDefaults) {
+//      _.assign(integrationRequestTemplates, {
+//        'application/json': this.DEFAULT_JSON_REQUEST_TEMPLATE,
+//        'application/x-www-form-urlencoded': this.DEFAULT_FORM_URL_ENCODED_REQUEST_TEMPLATE,
+//      });
+//    }
     // set custom request templates if provided
     if (http.request && typeof http.request.template === 'object') {

i am facing the same issue…but i cannot update the serverless stack.

samiya03 I faced the same issue. I opted for overwriting the mapping template in the serverless file

              application/json: '$input.json("$")'

This allows whatever you pass in to be passed through while the application/json mapping template is used.

The following lines will disable default mappings:

               application/json: null
               application/x-www-form-urlencoded: null

Related GitHub URL Issue 7008 default request templates by jormaechea · Pull Request #8159 · serverless/serverless · GitHub