In this video, we are going to continue the development of order, acknowledgment microservices and
in the last video we have left the third and the first step.
If you go to the our indexes, you can see that we are going to develop these two steps.
And now I'm going to focus on the third step, which is the published message to topic on Amazon.
Since using the SDK libraries.
So before we start, it is good to check the documentation.
If you open the source client documentation, this is the library for a SDK.
You can see that we will use publish command and if you open the publish command, you can see all the.
Basically it is send a message to Amazon sans topic and we will use these publish command in our example.
If we send a message to Amazon says topic, Amazon says delivers the message to each end point that
is subscribed to the topic.
And the format of the message depends on the notification protocol for each subscribe.
And in our case our subscriber systems are case.
So we will use a SCS protocol for subscription to Amazon sans topic.
Okay.
If you come back to the documentation, you can see the publish command.
If you scroll down here, you can see the example usage and you can check the input and outputs from
the objects of the published command input.
Here you can see that we will provide these information publishing an item into the sense topic and
also you can see the publish command output.
This will return us to message ID and sequence number.
Okay, let's get started.
The first thing we should create the client object.
So when it comes to work, any sense?
Object.
Client object.
First thing we should do is create separate client Node.js module in order to interact with sense client
object.
To do that, I'm going to open the command text and I have listed what we have done, what we are going
to do.
In this video, we basically examine the source client documentation and now I'm going to create a sense
client JS file and implement this Node.js function.
If you create a sense client JS and implement this code, this will be provided to interact with this
client.
We have done these methods before when we interacting the source SDK operations and after that now we
can implement our actual logic.
But before implementing the actual logic, it is best practice to use a lambda environment variables.
So before start coding, it is good to create a source topic run as an environment variable for order
acknowledge lambda function because we will use the aaron of the topic in the development of to publish
message when we are providing the request parameters of the publish command.
So for that purpose I'm going to open the or a console and first of all go to this topic and get the
Aaron over to our order topic.
If you come here, go to topics and open the order topic, you can copy this.
Aaron And after that, go create, go to lambda of the management console and open the order acknowledgement
lambda function and go to configuration.
And if you go to environment variables, I'm going to create an environment variable at any one table
which the value should be the or order topic.
Aaron And the environment key will be topic.
Aaron Please give and provide this environment variable copy from the order topic.
Aaron And paste in the key of the topic.
Aaron And click this button.
So we will use this environment variable into our application.
As you remember that this is the best practice.
Get these names from the environment variables into lambda function.
By this way, we don't change any Aaron if we are since provider is changed we only change the value
in here.
Don't change the lambda actual function code.
If you open the our actual code now we can publish message to the sense in our lambda function code.
So basically the idea is the same.
We will prepare for the parameters.
So I'm going to create a parameters.
First, in the parameters, we are providing the message as a order request that we are prepared in
the first two steps and after that we are pacing the topic.
Aaron See that we are getting topic Aaron from process start and we the topic Aaron that we provide
in the last couple of minutes.
So after that we pass these parameters to the publish command.
So in order to do that, I'm going to import record statement.
So this is very important to add a required import statement, go on top of the page, and after that
we will import the required package with importing publish command from the SNS client and also import
source client.
JS Separate module object to send required commands in our application.
So after import these two statements, if you scroll down, you can see that our published command makes
green and now we can send these publish command with using these parameters.
And one of the.
This comes from the lambda environment for us.
Okay.
That means we have successfully performed the third step, which is the published message to SNS and
we are log the operation which is incoming from the published command data.
Okay, very good.
Now it is time to develop the fourth step in order to perform the fourth step, which is the save order
item in dynamic DB.
I have created on the command text file and several documentation.
We will follow the same steps.
First of all, we will check the documentation.
We have already know that dynamo DB client documentation from a SDK, but this time we will use put
item command.
You can check the put item command.
This will be basically insert an item on Dynamo TV and here you can see the input and output.
When we are inserting any words from Dynamo DB, we will use also util dynamo DB library to make it
simple.
And these are the input parameters and these are the output parameters.
OC After that, if you come back to our documentation, basically we will create the Dynamo DB Klein.
JS This we will separate the Dynamo DB Client Node.js module.
If you open the DB client JS, please create this file and implement this code.
Have already know that this could provide to interact with Dynamo DB and if you come back the other
items, the other item is set to environment variables.
Again, I am going to open a maven console and go to configuration environment variables and I'm going
to add new environment variable for the dynamo db table name is note that we will create an order table
and I would like to get the table name from the environment.
Variables of the order acknowledgements lambda function and click this Ableton.
Okay, very good.
We have now to my tables and now I'm ready to implement our Save Dynamo DB operation.
If you come back to our index case and go to the save order item in Dynamo DB path and now we will follow
the same steps.
Basically this time we will use put item command and Marshall and Marshall operations from the util
dynamo DB and I will use the Dynamo DB clients to do that.
I would like to start with the adding to import segment because it is very important to adding record
import statements.
So please add the correct import statement as well as like me, you can see that we are adding to put
item command in Dynamo DB client object and also we are using Marshall and Marshall from Util Library.
And lastly, I have added to Dynamo DB client from our separate Node.js module to interact with Dynamo
DB OC.
After that, after importing these statements now we will develop our actual operation.
So for that purpose I have prepared a dynamo DB parameters and after that paste these parameters into
our client object.
So you can see in this line of code we will provide this line of code in action for the for this action.
Basically here you can find the dynamic DB parameters.
Placing the table name and table name comes from the environment variables and placing the item.
So if you check the item, this is the order request.
So we will prepare the order request from the incoming event.
But that's why we will validate and that's why we will set the ID as a UID because ID is the order partition
key and we have to provide these ID information, otherwise it will get exception.
So by this way, we can pass the whole order request as the item of the Dynamo DB table.
Of course, using the Marshall Utility Library.
Okay.
After preparing the Dynamo DB parameters, the others are very similar.
We are using the put item command to insert any item and sending with using the dynamic DB client object.
And we got the create result and we are logging that successfully.
Create an item on Dynamo DB OC.
As you can see that we have successfully publish topic on Amazon SAS using a SDK libraries and after
that we will save item on Dynamo DB order table.
So we will finish the development of the order.
Acknowledgements with interacting sense and Dynamo.
DB Table.