Lambda Function Code
Explore how to develop a Lambda function that verifies ingredient availability by querying DynamoDB, updates inventory for sufficient ingredients, and returns appropriate success or failure responses. Understand the code structure, database interactions, and error handling within AWS serverless workflows.
We'll cover the following...
In the previous lesson, we created a configuration code for Lambda as well as all needed permissions. Now, we can focus on the actual code.
Check ingredient availability
Let's start the coding part. Below, we can see our project:
Let's open a file named ingredientPreparation.ts from the handlers folder and add the following code:
First, we'll check if the required ingredients are available in the inventory. We'll iterate through the requiredIngredients list and get each ingredient's availability from the DynamoDB table.