serverless-offline ignores custom status code

Created on 9 Jun 2019  路  5Comments  路  Source: dherault/serverless-offline

I tried to configure serverless to return a 204, but after struggling for a while and deploying, it turns out serverless offline is not handling custom status codes properly.

Using an empty function:

module.exports.hello = async () => { 
  // do nothing
};

and the following serverless.yml file:

service: test

plugins:
  - serverless-offline

provider:
  name: aws
  runtime: nodejs10.x
  stage: dev
  region: eu-west-3

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: test
          method: GET
          integration: lambda
          cors: true
          response:
            statusCodes:
              204:
                pattern: ''

You can reproduce the issue by calling the endpoint locally:

$ curl -D - http://localhost:3000/test
HTTP/1.1 200 OK
vary: origin
access-control-allow-credentials: true
access-control-expose-headers: WWW-Authenticate,Server-Authorization
cache-control: no-cache
content-length: 0
Date: Sun, 09 Jun 2019 10:03:57 GMT
Connection: close

and deployed:

$ curl -D - https://whatever.execute-api.eu-west-3.amazonaws.com/dev/test
HTTP/1.1 204 No Content
Content-Type: application/json
Content-Length: 0
Connection: close
Date: Sun, 09 Jun 2019 10:03:24 GMT
x-amzn-RequestId: d1ba59d9-8a9d-11e9-b887-6ff35cfdb83c
Access-Control-Allow-Origin: *
x-amz-apigw-id: bAbo8FRhCGYFVgw=
X-Amzn-Trace-Id: Root=1-5cfcd96c-aecdcffcf84993249296f498;Sampled=0
X-Cache: Miss from cloudfront
Via: 1.1 e3572bc2867545c7e2bf0953e1795991.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: LHR61-C1
X-Amz-Cf-Id: buAkx6Ft8RgDrCu0mMRElU2ZIR3zCFPrZzWRkRJ5wasTxB1baqFDTg==
bug help wanted

All 5 comments

Hello @frsechet, I will work on both bugs soon.

No worries, thanks a lot for what you do! They are not urgent to me. I would gladly propose a PR but I am quite in a rush for now, sorry about that. I will surely contribute something over the summer :-) (and/or buy you a beer as we are both in Paris!)

Found another one while writing this one: try curl -I on both requests (offline/deployed) instead of curl -D -. Deployed generates a 403 (because there is no http event for HEAD requests), but sls-offline gladly accepts it as a GET. Would you like me to open another issue for that one?

Yes another issue would be nice thanks :)

Hi, could please let me know issue has been resolved

Hi there, this issue has come up where I work and I would like to start working on this. I was wondering if someone who has experience with the codebase or knows anything about this issue would be willing to give me some thoughts or input. Thanks.

Was this page helpful?
0 / 5 - 0 ratings