dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

Body is undefined while running local #4

Closed lopezjurip closed 7 years ago

lopezjurip commented 7 years ago

Can't be run locally, perhaps event is empty

serverless  invoke local --function handler --log
Type Error ---------------------------------------------

     Cannot read property 'body' of undefined
lopezjurip commented 7 years ago

Using a event.json like:

{
    "resource": "/users",
    "path": "/users",
    "httpMethod": "GET",
    "headers": {
        "Accept": "*/*"
    },
    "queryStringParameters": null,
    "pathParameters": null,
    "stageVariables": null,
    "body": null,
    "isBase64Encoded": false
}

and running:

serverless  invoke local --function handler --log --path event.json

Works well

dougmoscrop commented 7 years ago

This would be by design I think - I'm open to suggestions on how you would like this to work; this is sort of a problem with serverless invoke, which is why there is a discussion to make like serverless invoke http because a regular lambda invoke and an API Gateway invoke are quite different

dougmoscrop commented 7 years ago

Would you accept that if event is undefined, it defaults to:

{
  "method": "GET",
  "path": "/",
  "body": ""
}

?

lopezjurip commented 7 years ago

Looks like a razonable default 👍

dougmoscrop commented 7 years ago

Released v1.1.0 with this in it