using this https://github.com/pmuens/serverless-crud after installing it, I am able to run a test from the api gateway console with no problems. I use this event data: {“id”:“334”,“note”:“this is another note here.”}
However with the same event data in the event.json file and calling invoke from cli like this:
serverless invoke --function create -p event.json
I get an error: 2016-10-14T21:03:32.404Z aa04dba8-9251-11e6-9d7a-4d5ce2f4cb21 SyntaxError: Unexpected token u
at Object.parse (native)
what i notice is it converts the event payload to use single quote instead of double, which i think is why it errrors out: { id: ‘335’, note: ‘this is another note here.’ }
I am encountering this now. I have set up a basic RESTful set of services. Everything works fine, and I can use Postman, curl, etc. to execute through the API Gateway. But I would like to invoke my lambda functions from the CLI directly. The problem, as mentioned here, is that I am trying to parse already parsed JSON (e.g. JSON.parse(event.body).
Is there a pattern that is being followed to address this?
@bush if you invoke your Lambda from directly from the CLI then you need to pass in an event object that looks like the one the API Gateway would pass. This means the body needs to be a string containing your JSON object. In simple terms body = JSON.stringify(YOUR-JSON-OBJECT).