In this video, we are going to do Hands On Loop, which is the ADA lambda event filtering from SXSW
data.
So that means we will extend our on loop with adding the event filter when pulling message from the
case to a lambda.
So what is lambda event filtering basically for Amazon Kinase Dynamic DB or Amazon case event sources,
we can use event filtering to control which events lambda sends to our function for processing.
For example, we can define filter criteria so that we process only the records from the kinase streams
or the Amazon case that have the status quo is success.
Also, we can define a five different filters for the single event sources if one satisfies any of one
of these five filters.
Lambda sends the event to our function and execute the function.
Otherwise, Lambda discard the event.
That means if the event criteria is matched to our criteria filter, then this will be triggered database
lambda and invoke the function.
If the criteria is not match this filter, then lambda discard the event and not execute the lambda
function.
So how we can apply this event filter?
Before that, let me show you documentation that we can apply.
Also, if you open the Lambda event filtering documentation, you can see the basics of the event filtering.
You can see that we basically provide the filter and the patterns in here in adjacent format.
If you scroll down, we can edit data and data one including this structure and we can paste the pattern
one out pattern to.
This will be look at the matching the criteria and execute the lambda function.
Okay, very good.
And this is an example incoming message from the kinesis that we can use and filter this message according
to Data City and so on.
So now let's define our use case and put the event filter in our cases.
So as we can see that we have developed our lambda polling infrastructure and now we have already read
the queue, but now we are going to put event filter and see how what's happened.
So basically we will create a corporate customers and we will either individual customers think about
that.
This is the customer create queue and Lambda will be create a customers and the customer has two types.
One type is corporate, one type is individual, and then the only creates for the corporate customers.
So that's why we put the event filter and check the incoming message from the case and check the type
of the customer is the type of the customer is corporate.
We will invoke lambda function and if not, we will discuss the event and not execute the lambda function.
It is open the visual code and we will design our events from the case and also event filtering.
As you can see that we are designing the corporate customers, we will create corporate customers and
lambda only interested the corporate customers and we are going to create customer payload for case
message.
So you can see that this is the our message one, this is the customer ID name and the type is a corporate
and this is the message two, which is the customer ID to name and the type as a individual.
So we only interesting with the corporate customers in our lambda function for that purpose we will
add this event filter.
This will be get the body information and this will be body of our case record message.
And after that we locate the type and check the type as a corporate.
If the corporate these message execute and invoke our lambda function.
If not this message discard from the direct discard from the lambda not execute the function.
Okay, let's start implement.
Please open the console and go to our lambda function.
And if you come to function and come here, go to configurations triggers and I'm going to delete this
trigger and we'll add from the scratch.
Please delete the existing trigger and make sure that this will be clear from your page.
It is subtle is deleting.
It takes some time to delete the trigger from the lambda function.
So please wait.
Since this the operation finished and after that we will start to create a trigger again.
If you refresh this page, you will see that the delete operation is successfully finished and we don't
have any trigger now.
And I'm going to add a new trigger, and this time we will select the case again.
Please select the case again and select the queue as a micro and don't change the base size and the
batch window and click additional settings.
If you expand these additional settings, you can see that the filter criteria that we can define in
our example.
So I'm going to add a filter criteria and we will add the filter criteria is a JSON format.
You can see that this is a wallet JSON format.
It is expecting from the filter rule.
You can get the JSON from this documentation.
And I have created our case the JSON documentation from we just do.
And copy from here and come here, paste in here.
So basically we will filter the type information into the body of the message and we will check the
type as a corporate.
If the corporate, we will execute the normal function.
Click the button.
Okay.
We will add one item we don't need to.
You can add one more item as a filter criteria.
I'm not going to add one more item if you scroll down.
Click the ed button in here.
This will be create trigger, which is the trigger.
But this time this trigger has filters.
If you scroll on, go to configuration triggers, you can see the details in here, in the details.
If you scroll down this time, we have a filter criteria and we are looking to body type as a corporate.
Okay, very good.
So this instructs lambda to process only the records where the type is the corporate.
So wait until is finished.
You can see the state is creating.
Refresh this page and see that the state is enabled.
So that means we will send message to our queue and see what's happened.
So I'm going to go to Amazon queue and come to our queues.
Open the micro, click the send receive message and we are going to send message now.
So the first message is sending the corporate.
So this will be execute our lambda function.
We will send as a JSON format and click the send message.
Okay.
And the second message is individual.
So I'm going to copy paste in here and click to send message.
So we have sent to message into queue and let's see which one is executed in the lambda.
So go to lambda and go to monitoring and be in cloud, which looks to see the invocation logs.
If you go to cloud watch logs and open the latest log stream, you can see that only one invocation
happens.
If you open the incoming event JSON object, you will see that in the body of this information we have
only corporate type in customer will be executed in our example.
And if you see the next log, which is the incoming body information, this is the corporate customer.
So that means we have successfully filtered incoming message with pull based invocation from the lambda
with adding the filter in the trigger of the A lambda.