Writing Our First Create Lambda Code

Learn to write lambda code to create reservations through the POST method.


This time we’ll use TDD to develop our application. For our first code, we’ll be very explicit about the thought process. Later on, this will become implicit because this course would become way too long if we built all our code incrementally, through frequent testing.

The first thing we want to do when we receive an event in our Lambda is to change it into a format we can actually work with and conduct some checks to see whether the information we received is valid (never trust frontend data). For example, we should confirm that the end date is later than the start date.


Create a folder under create called __tests__. Because we only have one function right now, we’ll put almost everything we write in the directory of the Create Lambda. If we notice we need certain functions elsewhere, in another Lambda, we’ll move them to a common module. Create a folder called specifics under our test folder. We’ll call our first test file anticorruptionTest.ts. In DDD, an anti-corruption layer is often our first line of defense against the outside world. It can check incoming information and transform it into something that’s actually useful to our domain. This layer’s modest, in our case. Add the following to the file:

Get hands-on with 1200+ tech skills courses.