Hello, I have been chasing what I thought was a bug in my code but turns out to be a difference in the way the event is handled depending on environment.
In my development flow I use
sls invoke local for quick checks and the sls offline plugin with PostMan for more detailed debugging. Then I deploy to AWS and use
sls invoke for another quick check and PostMan to
confirm the API Gateway endpoint is functioning as expected.
As soon as I introduce parameters in the form of an event everything goes haywire. It seems that some cases parameters are on the event and in other cases event.body after JSON.parsing it. I have documented each case and it's results in https://docs.google.com/spreadsheets/d/1QJOak5XlZuX0-ETHTbpV4ScFvp2uvsIwQl7IvmHhH_g/edit?usp=sharing.
Can anyone enlighten me:
- Is this normal behaviour?
- If so, why?
- What is the established best practice for managing it? Should I use environment variables, attempt to JSON parse and act on success/fail, something else?
For now I have simply added
let params = (event.body) ? JSON.parse(event.body) : event; as the first line inside each handler function and it seems to be working. But I lost a lot of time getting to this stage.