529583 (3) [Avatar] Offline
I have a problem with the exercise at the end of Chapter 3. Using the solution code in the book, the following cases work: passing in both a greeting and username, passing in a greeting but no username, and passing in no greeting and no username.

However, if you try to pass in a username but no greeting, the request body mapping template spits out an empty json object to the lambda function, essentially just causing the username to disappear into thin air. This is quite bewildering as it's definitely going to the right route and lambda function, but for the case of a username but no greeting, it just throws out the username.

Anyone have any ideas?
adamba (6) [Avatar] Offline
In the Integration Request, what is your Body Mapping Template for application/json?
150034 (6) [Avatar] Offline
There doesn't appear to be an easy answer to this problem.

If you change the body mapping template for the integration request to generate a Method request passthrough and then run test events with a username but no greet, you'll see that the path object is empty in the endpoint request body. On the other hand, the object is not empty if only a greet is set but no username.

In other words, the body mapping template can't work, because API Gateway is not passing the username parameter when the greet parameter is missing.