Instructor: 0:00 There's one more thing to we have to fix in our API. Right now, every single todo item that we are going to add to the list is going to get a totally random id, which means that we cannot add more than one item to the list, because in DynamoDB, every item has to have a unique partition key.
0:33 First, open up the terminal, navigate to the Lambda directory, and here I'm going to run npm init -y in order to create a package.json. Once our package.json is created, I'm going to clear the terminal and run yarn add uuid package. For the record, you can also use npm. I just happen to use yarn. Since we are using TypeScript with our Lambda function, I'm going to also install yarn add @types/uuid.
0:58 Next, import the uuid package over here. I will be using the version 4 because as we can see in the documentation, "This version is entirely random created from cryptographically strong random values." This is more than enough for our use case.
1:12 Next, instead of using this totally random id in our @todo item, I will be using either an id which was provided by our frontend in the data object or I would be generating an entirely random id using the uuid package.
1:27 Let's strip it. In our terminal run yarn CDK deploy. Before we test our API, let's take a look at our Lambda function in the AWS Console. Here, from CloudFormation let's go ahead and click on the physical id of the Lambda function.
1:40 In the AWS Lambda Console, we can see that not only our to-the-handler.js is here, but also package.json, yarn log, and all of our Node modules. All of that was packaged by CDK and deployed to the Cloud for us. Yet another thing that we don't have to maintain ourselves.
1:55 I'm back in Insomnia in order to test the API. Sending a get request is getting me all those todo items. Let's add a new one. I'm switching the get request to post and setting the body to a JSON and over here I'm going to do todo test todo, and then send that.
2:10 As you can see, the test todo was added to the database. Let me delete that. Let me switch to get again, clear the body and I will be sending request to get all those todo items.
2:19 Here you can see that our test todo was added to the database and also it has received a completely unique random id.