In this video, we are going to continue to create our infrastructure for public subscription architecture
with using SAS case and Lambda.
As you remember that we have left only one service, which is the Amazon sions that we will create during
this video.
So let's create Amazon SAS and topic.
Please open the console, go to SAS and topics and click the create topic.
So we will select the type of the topic as a standard, not FIFO.
Please select this on that and give the topic name as an order topic.
And if you scroll down, I'm not going to change any configuration and go to the create topic button
and click this button.
So as you can see that we had success to create order topic and now it is time to subscribe this topic
from the sky schools.
So if you go back to our architecture and see that we have three Qs that will subscribe to Amazon sans
topic and this will be subscribed from the Qs one for the notification queue, inventory queue and shipment
queue.
All these three Qs will be subscribed to Amazon topic and get the message from the SMS topic and this
message will be consumed and pull from the downstream microservices.
So now we should create subscriptions from Amazon to SNS to provide the message delivery for that purpose.
Please open the console, go to the order topic and if you scroll down you can see the subscriptions
and we don't have any subscription.
But according to our architecture, these three SKUs should be subscription of our SNS topic.
For that, we will click the create subscription button and select the protocol.
In our protocol will be Amazon SP Q and the endpoints will be all these three.
Q So I'm going to select one by one and I'm going to create subscription, but you can check the subscription
filter policy and drive policy.
We don't set any configuration.
We only set the protocol case and we will give the endpoint as a inventory cue and we will create subscription.
And as you can see that the subscription creates successfully.
If you come back to order topic, we can see the subscription list has one item now, but I follow the
same step for the other Q's.
Click to create subscription, select the SKU and this will be notification.
Q So scroll down and click the subscription and go back to the topics again.
Order topic, scroll down, go to subscription, create subscription, select the case and end point
will be shipment Q, scroll down and create subscription.
If you come back to order topic and scroll on, you can see the subscription systems are three SKUs
which are the inventory notification and shipment.
So that means these SKUs successfully subscribe to our order sense topic.
But it is not enough because in order to publish message to the Amazon excuse after provide to subscriptions,
it is also required to giving permissions.
So that means we should give required permissions to Amazon sans topic in order to send message to the
Amazon SKU.
For that purpose, Amazon says topic should be able to send message to the Q.
We have to set a policy on the Q that allows the Amazon topic to perform as send message action.
So that means we should give required permission, which is the send message permission into the our
case, which will be triggered from the Psns.
So in order to do that, I'm going to go to the old cues one by one, and I'm going to set the principle
to Amazon services.
So let's go back to our advertisement console and open the excuse and we will open one by one and edit
the access policy of these Qs to provide to accommodate incoming message from the PSNS.
Let me start with immature Q Please open the queue and if you open the queue you can see that we have
access policy settings.
If you come here, you can see that this is the default settings that is provided to principal from
the root directory.
But we need to set and change these access policy in order to send message from the Amazon SNS.
To do that, we have to set the principal as the Amazon service.
You can come here and you can change these principal, as Amazon says, in order to do that, I'm I
have created separate lecture and section folder into our widget pseudocode.
You can see here we are in this step we have created the Amazon sans topic, which is the order topic.
After that we have subscribed from the old excuse and now it is time to set principal to be Amazon service.
So I'm going to open one by one old school SKU and change the principal value as a service which is
the start of Amazon dot com.
So if you come back to our console, I'm going to change this line of code page, click the edit button.
If you scroll down and come to here, we basically change only this principle service.
So I'm going to change this principle, add this to the service.
So that means we are giving an allowing the service of the SNS to publish message to a space.
That means we are giving all actions about the space, but we are particularly interested with the send
message action.
Okay, so after change this principle, scroll down and click the save button.
We have successfully changed access policy for the eventual Q and please follow the same step for the
other Qs.
Go back to Qs, open the notification service, come to access policy, edit policy, scroll on.
Change this line of code from a service of SAS.
So scroll down and click the save.
Okay, I'm going to follow this same step with the shipment.
Go accessibility, click the edit button, scroll down, change this line of code, scroll down and
click this button.
Okay, very good.
So that means we have successfully give required permission and we are now ready for the publish message
from the Amazon Sans.
And this will be subscribe from the TV HQ HQ and this will be consumed from these downstream microservices.
So now it is time to test publishing sense message.
For that purpose.
Please go to the main console, go to Amazon source topics and open the order topic and click the publish
message.
So I'm going to send the message which is the subject as an order placed.
This is our use case.
And if you scroll down here, you can see the our message body.
So I'm going to put a JSON.
But the information which is basically order place JSON, this is the item status and the type including
this JSON, you can increase the attributes.
If you scroll down, I'm going to publish the message, click the publish message.
So a message published successfully that means this message is published from the Amazon since unsubscribe
from the excuse and these queues are consumed by the pool by the distance to microservices, that means
if I go and go to the notification microservices and go to cloud which looks I should see that the invocation
happens from the SAS s case and the lambda function.
Let's go to the lambda function and see the invocation comes or not.
Go to Lambda Page.
Go to functions.
Open the notification microservices.
Go to monitor and weave in cloud watch logs.
So if you open the latest log in cloud which.
We should see the invocation.
Yes, the invocation comes in here.
Here.
You can see the invocation comes successfully in order to see the incoming event JSON object, we should
log the incoming event for that purpose.
I'm going to change the lambda function code so we should look the incoming event for all our lambda
function.
I have put one more step which is the adding console log line of code into all lambda functions.
Go to lambda functions and please add all log operations into all functions.
Go to notification microservices in the code window.
We should update these function and click the deploy button and go back to functions.
Open the shipment, go to code window and copy paste from the log operation.
Click to deploy button, go back to functions, open the inventory and come to code window, paste the
location and deploy this button.
And also we have one more micro source, which is the order acknowledgment.
Please come here and paste the logo patient and deploy the function.
Okay, now I'm going to follow the same step, which is the sent publish message from the order topic.
Click the publish message and this subject is an order placed.
Scroll on here you can see the our JSON object, which is the body of the message.
And if you scroll down and click to publish message, this will be triggered or three downstream microservices.
We're using SAS case and lambda function.
So now if you go back to lambda functions and if you open the notification microservices, if you go
to monitor and we've in cloud watch logs, we should see an invocation and also incoming logs.
Yes, there is another log stream if you open this log stream this time we have got the incoming event,
JSON from the SDKs.
You can see the this whole event JSON object.
I'm going to copy this JSON object and open the our pseudocode and come here and paste into event JSON.
So if you come at the beginning of line and remove this line and save these as a JSON, you can see
that we have a record collection since we published one message, the record count is one and in the
record we have message ID received handle and the body information.
And if you expand this body information, this is comes from the Amazon sans.
So that's why it is very long sitting and as you can see that this is type as a notification message
ID is different.
So that means these skills body information also comes from the SAS.
And if you go back to internal body you can see this object is order place and if you come to message
we can see another JSON format which is our actual payload, including the item, iPhone, also status
and so on.
So that means if you come back to our architecture and see that we published message from the Amazon
SAS and we provide a JSON object into message body and this will be subscribed from the Amazon excuse
and also an excuse to create a record and this record pull from the notification lambda microservices.
And that's why we will see these nested object into the incoming event, JSON or Lambda functions.
Well, if you come back to our object, you can see that we have a nested object.
If you go back to notes and come to notes here.
Okay.
But then the page.
And after we check the logs, we saw that we have a nested object.
We can go actual object from the case records, body, sions, topic and the message which is the actual
order message.
So we need to react this order message with this line of code records zero body and the message.
And after that we get the JSON object and we will pass this JSON object in order to reach our actual
object.
Okay, very good.
As you can see that we have successfully create our infrastructure and we have test a published message
from the SNS and we have verified that all these services are working fine.
But by the way, all these infrastructure create operation can be handled with the infrastructure as
called tool in a place like cloud formation, some or CDK, we will see these infrastructure as called
deployment frameworks in the next sections.
So we have successfully create our infrastructure.
Now it is time to focus on the second part.
So what was the second part?
It is developing.
Learn the actual code for interacting message.