In this video, we are going to create infrastructure for Amazon event with each custom event plus with
following the event driven architecture.
Here you can see the overall architecture that we are going to build in this Hands-On Lab.
Basically, we had created API Gateway Basket, Micro's, Lambda function, case order, queue, order
microservices, notification microservices.
And now we will create the event bridge custom event pass.
So we will create event bridge, Amazon event bridge, custom event pass.
So this will be the basket checkout event pass.
And before we start, we should analyze and design our custom event pass.
We can see the big picture, basically event which has three main core concepts that we need to create.
The first concept is custom event.
Plus we will create a custom event pass into event bridge, which will be name is checkout pass, event
pass.
And after that, in the second step, we will create an event rule with the event pattern.
So we will create a custom event rule, which will be the checkout basket rule.
And after that, we will create targets.
So that means we will create a target of the event bridge as a case and also notification microservices
for our custom event bus.
With this plan basket microservices invoke from the API gateway from the HTTP post request and basket
microservices publish the checkout event checkout basket event to the custom event pass and checkout
basket event pass process the event rule with the event pattern and after that, publish the event to
the target systems.
So let's get started to create these infrastructure into our environment.
Please open the event console and go to Amazon Event Bridge and we will start with creating a custom
event pass.
If you go to the event bus, you can see that we have only default event passes, but this time we are
going to create a new custom event event pass.
You can see in here and click this custom event pass.
So I'm going to give the name as a custom multiverse, which is the checkout basket event pass.
If you scroll on, I don't change any configuration and you can see the store space policy and event
archive and schema discovery.
So give the name the bus, custom bus and click the create button.
Okay, we have created our customers.
Which name is checkout basket event?
And the second step we will create event rule with the event pattern.
So we will create checkout basket rule.
In order to do that, we can go to the our custom event pass and you can see in here the details of
our event plus what I would like to create a rule.
So for that purpose, go to rule section from the left hand side and click the create rule.
And you can see in here we can define a rule in this test, but before that you forgot the very important
thing.
If you go back, basically we will create rules.
First of all, we should select event pass.
Since we have create custom event pass, please select these event pass in here.
We will create rule into our custom event which is the checkout basket event pass select these custom
event pass and after that click the create rule button.
And now I'm going to define a rule name, which name is checkout basket rule?
And if you scroll down you can see that this rule will be create our custom event pass and we will use
rule width and event pattern.
Click the next button and see the next step.
And the next step is will event pattern is.
Remember that we have created event pattern in the last sections and we understand the sample event
section and also event pattern section.
So basically the event source of these custom events should be a base event and I'm leaving as it is.
If you scroll down, I'm not going to sample event.
Now, I will explain after that go directly to event pattern and we will create event pattern from the
custom pattern if you come here and we will provide a custom pattern which will be the JSON object.
And if you copy paste this code, I'm going to copy and paste from the our pattern into common text.
We can copy from here and.
Certain.
Okay.
This will be our event pattern.
So if you go back to our estimation console, we have provide this custom event pattern which expected
detail type is a basket checkout and source is a these are application name.
Okay.
So now if you test this pattern is matching or not, for example, go to sample event and select the
three.
Again, if you select the object, create a three event and test these event pattern from the event
pattern box.
Let me test this event.
Yes, test pattern is you can see that the event didn't match because we are expecting detail type as
a checkout basket.
If you come here and change these object created to the our basket event and the source is what we have
expected, not the SX three.
We are expecting these custom application name so you can specify some some custom object in here.
For example if you copy paste from here.
And come here and change the detailed type as we expected in here.
Think about that.
We are triggering and checkout basket event.
The source will be the application of the OR.
Application name and that means we are checkout event from the basket microservices and there is also
detailed JSON object which including the order ID and order name and so on.
You can think these think that this is the event JSON object that expose and the trigger from the basket
microservices.
Okay.
Let me test this incoming event pattern.
So this time, as you can see that it is made.
So that means we are expecting detail type, checkout basket and source this application name.
After we have defined the event pattern, we can click the next button and the next section is a select
target.
So this is also very important step.
We will create Amazon Case Order Queue and notification microservices for targeting our custom event
pass.
For that purpose I will add to target.
The first target is of course a W services and this will be the case.
You can see the school and specify the queue of the order queue.
Okay.
And I would like to also add another target which is the ADA service and this time lambda function.
Which will be the ah notification microservices.
If you go back to our architecture, you can verify that the subscriber of the event will be excuse
and notification service.
Okay.
These are the targets of the Amazon event customers and we have defined a square SKU and lambda function
and click the next button so we don't have any configure text.
Click next button and review and create.
Here you can see the rule name as a basket checkout basket rule name and you can see the our event pass,
which is the checkout basket event pass and you can see the event pattern.
This is the JSON format, detail type and source.
If you scroll down, we have to target order queue and notification microservices.
After that, please click Create Rule Button.
As you can see, that we have successfully created our rules.
If you can't come to rules and select the event, pass as a checkout basket event pass.
You can see the listed rules in here.
We are rule name is a basket rule name.
Here you can see all the days of the rule.
So that means we have finished the create infrastructure part and for custom event each event pass,
we basically follow these three steps and create custom event pass and create event rule with the event
pattern on the custom event pass.
And lastly, we will create targets which will be the case and notification microservice lambda function.
Now it is time to test our architecture for that purpose.
I'm going to send event from the Amazon event page and see that how invoke this event to our ordering
microservice and notification microservices to do so.
Please open the our analyst console and see that we are in the basket checkout rule.
And if you come back to event buses and come to custom event pass open the custom event pass, you can
see the send event button in here, click this and event button in here and select the event pass as
a custom OnePlus.
And here you can see the event source in here.
So basically if you open the do code, we have created our custom event with details of these attributes.
This is the name, rule name and the event pattern.
So in here when we are sending message event to the event bridge, it is requesting us from the source.
So I'm going to copy and paste as a source from our event pattern in order to match the event pattern
and redirect to event to the target systems.
So please copy paste from the event source in here and the tail type.
Also important, we should check the detail type as a checkout basket and make sure that your detail
type is correct.
And after that we are going to pass the event.
It is.
Think about that basket microservices triggered these events when the basket checkout operation with
the payload of the item and the price.
So please provide the JSON of these attributes in the event detail.
And if you scroll down, we are ready for this and when we are click the send button, this will be
some event JSON object from the Amazon event page.
And here you can see the our JSON object.
I'm going to copy and paste this event to the origin pseudocode.
If you can see here I have create several JSON object and paste in here.
Basically this JSON object produced from the event bridge and this will be run the our event page custom
bus and execute to rule event patterns and after that raw to event to the target systems.
So it will check the detail type and also source.
If these two attributes match, this is going to target systems.
So that means target system or case and notification microservices.
Now we can check the logs from the target system, which is the notification microservice and order
microservice.
Please go to lambda functions and open notification microservices.
So if you open notification and go to monitor and weaving cloud watch logs, we should see the implication
happens when we send event to Amazon event page.
Please open the latest log stream and see that there is incoming event from the event page.
If you copy this file and go back to our registry, the code, I have created a separate JSON file notification
JSON and if I remove this part, you can see that this is exactly the same what we have seen from the
Amazon event breach.
Okay, very good.
So a notification microservices is invoked from the event page and if you go back to our functions and
open the order microservices, these will be also see the invocations if you look at the cloud watch
logs, but this time these order microservices pull event from the space.
Please open the log stream and open the latest log stream.
See that this is incoming event JSON object.
This time we have seen a different object.
So if you go back to our wizard, open the order evaluation and here you can see the incoming event
JSON to order microservices say that it is a record error because all the microservices receive events
from the queue.
That's why we solve the records first of all.
And after that, in the body of the record, you can see the incoming object, which is the our event.
Each event object, we can see the detail type, checkout basket source and so on.
So our actual payload is into our details section.
So that means if we would like to reach actual payload, we go to record zero and after that, get the
body information in the body information, go to detail and decode the detailed information.
As a JSON object, we send the event from the Amazon event page and see the invocations from ordering
microservice and notification microservices.
These are the targets of the Amazon breach.
But what if I would like to differentiate the even.
Into the Amazon event breach.
For example, we are checkout event from basket microservices.
This event is related with older microservices but not related to notification microservices for that
purpose.
With Amazon event event rules, we can filter incoming events and sample events to the corresponding
service what are defined in the rule definition.
So I would like to separate the rule definition and separate the target from notification to all the
network services.
Now we will create a new event rule with event pattern.
Which rule name is a notification rule for that purpose?
Please open the a major console and go to the our event page.
If you open the event page, you can see that we have a rule section and select the our custom event.
Plus we have already checked out basket rule, but this time I would like to create a new rule which
name is notification rule?
So in this rule, if you scroll on this rule again with the event pattern, if you click the next button
and this time if you scroll down in the event button in the custom patterns, we would like to get the
same source, but the detail type will be notification.
So that means we can filter incoming events according to detail type and according to business case
and differentiate the target systems.
So I would like to put this event pattern as a detail type, as a notification and click the next button.
And this time target will be the again lambda function, but the lambda function will be the notification
microservices.
You can think about that if there is any notification event.
This event is not interested from the organic microservices, so that's why the notification event from
directly goes to the notification microservices.
But if there is a checkout event, this event is related for all microservices.
So that's why you check out what is triggered both ordering and notification microservices.
So that's why we can create a separate notification rule in order to target only notification microservices.
So if you continue or create operation, you can select the lambda function notification microservice,
click the next button, click next button.
You can reveal the or rule definition and click the create rule.
Okay.
Very good.
So this event rule only interested in notification microservices?
Not for the checkout microservices.
You can see the custom event pass.
You can see the ah notification rule is created successfully.
As you can see that we have created successfully for our infrastructure on the Hands-On Loop.
By the way, all these infrastructure create operation can be done with the infrastructure Esko tools
in a place like using the cloud formation, some or CDK, we will see these infrastructure as called
deployment frameworks in the next section.
And now it is time to focus on the second part.
As you remember that we have two parts when we are developing Hands-On Lab, the first part was the
create infrastructure.
On the second part is developing Lambda function code for interacting the event which now we will start
to second step which is developing lambda function code for interacting event bridge.