Welcome back to this challenge lab, implementing a serverless architecture
for the cafe, you know, the business case for this lab is basically
we want to create a lambda function in the private subnet one private subnet
to to extract the data from the RDS and generate the report.
And we will link that to a SNS topic that will send us basically
a daily notification once these reports are ready.
So let us get into it.
The first thing we need to do is to download the files as a zip file.
You need to keep them in your download folder.
I have them here in my downloads folder, so there is no need
to download them again for me.
Now, the first thing I will do is to go to NWS.
And from AWS I will go to Lamda
and I will create a Lamda function.
However, before I create the Lamda function,
I need to create a security group.
So basically, I'm going to go to the VPC
and from the VPC, I'm going to create a security group, and that security group
is going to be a lambda security group,
which basically open.
All outbound ports from the Lamda
without any inbound rules.
And just to create a security group, Now make sure before you do this step
that your lab is ready and fully created.
Sometimes you would face an issue.
If Adobe is not fully ready,
then I need to update the DB Security Group,
which is the security group for the RDS basically to accept the traffic
from the Lamda security group or create a new rule
because this is going to be much easier
and I won't face any issue with the permission.
So let me go back now to Lamda The creation of lambda function is going to be a bit
similar to what
we did in the first in the previous Lab
So you need to call this lab function, lamda Function Sails Analysis Report,
it's going to be Python 3.8 and you have to select an existing role,
which is the data extracting role And then you have to add the network layer
and you need to run this lambda function in the subnet
of a private subnet one and the private subnet two.
So you need to look here to the name of the subnet
that these are the subnet that you are looking for.
So this is private subnet one.
And I'm looking now
for a private subject two and this is private suddenly two
and the security group is going to be the security group that I just created
for my lambda function, which is basically accepting
no inbound traffic, but it is going to accept
doing or allowing all outbound traffic.
Now click on create function
and before you proceed, you need to pay attention to this.
blue bar here, which is basically saying
it creating the function sales analysis report.
You need that function to be fully created before
you can proceed with the next steps.
However, just to utilize the time,
I'm going to go and create another function,
which is another function that I need, which is the analysis report.
And then I will come back and configure this function here.
So we will
create now a sales analysis report, and this is the name of the function,
it will be Python 3.8 and the role will be an existing one,
which is the analysis report role
and then create a function.
Basically, this function is going to be also created,
but it will be faster in the creation now in the code.
You will be able to upload the code once the function
is fully and successfully uploaded.
So let me create save now.
If you go back to step number 15, we need to update the description
of this function and that description could go to the configuration.
You could do it from here.
The configuration and this is the description
and the timeout is going to be 30 seconds and then you click Save.
The next thing is when you want to do step number 15 as well,
they are asking you to update the handler and that's handler.
You can see it here below in the right time setting.
You click Edit and then you change the handler
to the sales analysis report and then you say.
Now let me go back to the previous function, which will take time to create,
and hopefully it's created still in creation.
So let us now wait for a few
minutes for this function to be fully appreciated.
We are now ready to do the sales analysis report data extractors
and in this function here we need to configure.
It's based on the steps as specified
in the steps in eleven.
And basically, we need to go to the configuration edit
and we put the description.
We put the description here in this function
to be around the function, to extract the data and time out
is going to be 30 seconds and then we save.
Next thing, I go to the code and I upload the code from the zip file
I have, which is the data extracted and then I click on Save.
See that sometimes you get this error.
Because the function is update in progress,
so you need to wait and try again, and sometimes the refreshing the page
will help you to get the function
ready to receive and upload the code.
And then click Save.
So the code now, is there
one last thing I need to do, which is in the right time,
I need to update the handler of the function to be served analysis.
The report extracted dot lambda
underscore handler.
Again, I have to wait
for the function to finish the update process, sometimes
the refresh of the page will do this.
Click Save.
So we are ready now.
We need to move to creating
the SNS topic now in the SNS topics
similar to what we did in the previous Lab we go to SNS.
And here we need to create
a topic called Sales Report Topic
and click next, and this is will be a standard and a description of it.
It's going to be the sales report topic.
Which is a display name just for us,
and then it creates a topic and then we create a subscription.
And this is will be an email and you can put an email here.
So you could use an e-mail that you have access to because you need
to see those report coming to your email
and then you create a subscription.
The next thing is going to go back to the lambda function
and from your lambda function, you need to go to the sales report,
sales analysis report and from the configuration,
you need to add an environment variable and you call this.
Topic ARN and
and you need to get the SNS topic area, and so let me open in this in a new tab.
And this is my topic.
This is the topic I just to create,
and this is like the air and I just need to put here.
And click Save
now, both functions are ready,
and I could move to basically to test the sales analysis.
So in this task here we are going to create
a test event from the cells and that is just to see that
everything is working based on our function.
Code is working as expected, so we click on
sometimes you will get a failure.
So feel free to review the steps in
step 24 to review which step you need to update
or which things you need to check before you can carry on.
So I'm going to
click on the test here, and i will call this testing
this new event and i will click on the test.
The idea here that you need to get
a successful result from the function.
The next thing is going to be in task seven to set up an event to bridge,
you know, in your event to create if you go to the services.
You can have an Amazon event bridge,
feel free to create a rule, and that rule, you can call it.
I think we have to call it a specific name.
No, you don't need to call it a specific name.
let say call it, sails report events.
And this is just
basically schaduled CRON expression.
No, you have to go back to review the CRON expression
if you want in order to basically finish this task.
However, in my case, I'm going to specify this.
CRON an
expression, which is basically this is will be a trigger alarm, the function
to run every time at 15.
Past 5:00 p.m.
every day.
And this is like the minute, the hour.
And basically, this is will be running every day
in a UTS time, and you can see now the verification.
This will be the next ten trigger data that you will have.
And this is like the sample event that you will get
now that the destination of the target is going to be a lambda function
and that's lambda function will be the sales analysis report.
So every time we've got a sense analysis, this is will be it triggers
the lambda function and it will also fly us by email.
Now, if you did everything successfully, you should receive an email to your email
address to accept and subscribe, and you'll receive an email
with the latest event
that was triggered from this event.
This is pretty much what you need to do for the snap.
If you like the content, please and
subscribe and support the channel Thank you so much.