3 Asynchronous work is easy, we Promise()

 

This chapter covers

  • Handling asynchronous operations with Claudia
  • The basics of JavaScript promises
  • Connecting to DynamoDB from Claudia and AWS Lambda

In the previous chapter, you created a simple API for handling pizza information and orders. You also learned that unlike with a traditional Node.js server, AWS Lambda state is lost between subsequent invocations. Therefore, a database or an external service is required to store Aunt Maria’s pizza orders or any other data you want to keep.

As Node.js executes asynchronously, you will first learn how serverless affects asynchronous communication: how it works with Claudia, and, more importantly, the recommended way of developing your serverless applications. As you grasp these concepts, you will see how easy it is to connect AWS Lambda to an external service, and you will learn how to use it to store your pizza orders by using AWS DynamoDB.

Because our brains aren’t good at asynchronous reading, and books are written in a synchronous manner, let’s go step by step.

3.1 Storing the orders

Ring, ring! You just had a short phone call with Aunt Maria. She is impressed by your speed, though she still can’t use your application, as you aren’t storing any of her pizza orders. She still needs to use the old pen-and-paper method. To complete the basic version of your Pizza API, you need to store your orders somewhere.

3.2 Promising to deliver in less than 30 minutes!

 
 
 

3.3 Trying out your API

 
 
 

3.4 Getting orders from the database

 
 
 

3.5 Taste it!

 
 

3.5.1 Exercise

 
 
 

3.5.2 Solution

 
 
 

Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest