In this video, we are going to develop the late product method for our product Lambda Microservices
using the HDC packages.
So that means we will accommodate the HTTP delete request from the client and Amazon API gateway into
our product microservices lambda function and to perform delete item in Dynamo DB table.
So in order to do that, please open the widgets to the code.
And in here in the indexes, we basically accommodate the HTTP delete method.
We're checking the exit method and case delete operation.
So which event JS object comes from our switch statement.
You can go to events and go to delete by ID JSON object.
This object is exactly the same event that we will trigger.
The our lambda function method will be the delete and the resource and pet in here.
So in order to get a pet parameters, you can scroll down and see that we can get the pet parameters
from the event dot pet parameters that ID information in order to delete an item in the existing Dynamo
DB table.
Okay.
So let's get start to accommodate this HTTP delete operation.
To do so, go to index case file.
And basically I'm going to add a new case block after the post operation.
This will be the.
KS delete operation.
Please add the next block, which is the delete operation and give the body of the statement as a delete
product method.
And this method get a parameter which is a product ID is the same way to get product.
In this case, we will delete product by ID.
So that's why we are placing event parameters ID to delete and specific ID to dynamic DB table.
So after we have performed the switch case below, we are going to develop the delete product method.
But before we implement, let's check the documentation.
If you go to the documentation, you can see that we will use the late item command.
If you go to delete item command, you can read what it is going to do and scroll down.
You can see the example implementation and if you go to the input object, you can see the available
properties that we will send as a parameter of delete item command.
So please go back to our indexes and save our index file.
Now I'm going to implement this delete product.
To do so, please go.
At the end of these indexes and we will create a new method.
You can come here.
Let me copy paste in here and explain after that.
So this is the delete product method, which is getting product ID as a parameter.
And we will use this product ID when we are deleting an item.
Before explaining these methods, let me add a required package.
See that we have all of the import marshal and in this case, the only thing that we should import the
delete item command, please copy this command or come here, click the control space and go on top
of the page and make sure that you have edit delete item command into the client dynamic DB package
and make sure that you have import successfully if you go back to our method at the end of the page.
So let me explain this method one by one.
So basically we will start with covering try case below to avoid any unexpected exception and follow
the exception from the Amazon Cloud, which looks after that we perform the log operation to identify
where in the delete product method and after that we basically create a parameter object.
You can come here and see the parameter object and let me make it more clean.
Okay.
We have created a parameter object with pasting the table name and the key information.
In the key information we basically passing the ID of the table because ID is partitioned and primary
key and with using Marshall it is very simplify.
Otherwise, for example, this is an example key definition.
Otherwise we should pass the ID information as a specifying number and the value.
Instead of that, we use the Marshall operation with directly passing the ID information without specifying
any data type.
And after we have completed the parameters, we pass these parameters into delete item command and using
the dynamo db.
Send a bait method in order to perform delete operation and response back to the later result logging
and return back these delete that to the delete product function.
So as you can see that we have developed this delete product function.
So in the next video we will see other methods.