Returning a 201 with serverless 1.x

Is there a way to specify a 201 response code instead of a 200 for certain endpoints?

Based on the guide (https://github.com/serverless/serverless/blob/master/docs/02-providers/aws/events/01-apigateway.md), it seems like this should be possible, but looking at the underlying code, it looks like the 200 response mapping is hard coded (https://github.com/serverless/serverless/blob/e4846edb21559d56104be678b1099b55f61f003d/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js#L272).

I was expecting to be able to do something like:

myEvent:
    handler: myEvent.handler
    events:
      - http:
          path: path/to/myEvent
          method: put
          response:
            headers:
              Content-Type: "'text/html'"
            template: $input.path('$')
            statusCodes:
              201:
                pattern: ''

Is this at all possible or should I just wait for the new HTTP response support via the Lambda proxy integration? (https://github.com/serverless/serverless/pull/2185)

When I looked at the source I also concluded that the 200 response was hard coded. Have a look at https://github.com/silvermine/serverless-plugin-multiple-responses as it might help you for now.

It looks like the master branch now has support for the lambda-proxy integration type. If you don’t mind your Lambda understanding HTTP then you can use that to send back a 201 :slight_smile:

Yeah my preference is to use the new lambda-proxy integration. Now that’s in master, I assume it’ll be a part of the next release candidate, so I’ll pick it up then.

1 Like

The master has now been released as 1.0 so you’re good to go with the proxy

1 Like