Section four, triggering Raspberry Pi with AWS cloud and ESP 32. In this section, we will learn the following introduction to AWS lambda, sending messages to ask us programming Raspberry Pi test triggering video 4.1 introduction to AWS lambda. In this video, we will learn the following. What is AWS lambda? Why are we using AWS lambda, creating a lambda function, creating an IoT rule? What is AWS lambda?
Lambda is a compute service provided by Amazon Web Services. It is basically an event driven serverless computing platform that runs your code in response to events and automatically manages the computing resources required by the code. Lambda runs your code. High Availability compute infrastructure. Using AWS lambda, you can also create your own back end services, or serverless applications. Lambda automatically runs your code in response to single or multiple events.
In AWS lambda, your code is executed only when needed. It is capable of executing a few requests per day to thousands per second, and you'll just need to pay for the compute time you consume and there will be no charge when your code is not running. To utilize this wonderful service, you will just provide quote to AWS lambda in one of the languages that lambda supports. This will be your only responsibility. All the operational and administrative activities are performed by AWS lambda on your behalf. But why are we using AWS lambda in our project, we need to trigger an event only in a particular condition.
Okay to be mortal. We will send the sensor data to the IoT Core. In IoT Core, we will write a rule, which will send the entire data to AWS lambda in AWS lambda, we will write a Python code that will check the sensor data. If it finds the temperature value to be more than 25 degrees, then it will send an on message to SQL. And when it finds the temperature value is less than 25 degrees, then it will send an off message to SQL s. So this code that you will run on AWS lambda is called lambda function. We will first create a lambda function in this video, and then write a Python code that checks the temperature values in the next video, creating a lambda function, log into your AWS account.
In Management Console, search for lambda, select it. Now, you will be directed to the AWS lambda homepage like this. Check region, it's not Virginia only. Here. On the right hand side, you can find create function selected. In this course, we will write our own Python code.
So select author from scratch, then give a name for your function, I will give my ESP 32 underscore function. Next, selecting the runtime. Here, you can find Python 2.7 selected. Now don't forget to check the permissions, select Choose or create an execution rule. Here, you can find three options. Check if create a new role with basic lambda permissions is selected.
This will automatically create a new role and we'll add all the basic policies required to that role and then create function. Yes, my ESP 32 underscore function has been successfully created here. On the left hand side, we can add various triggers manually like this. Okay, let's come back. In this video, we will add the trigger automatically. Now, are you excited to do this?
So come let's create an IoT rule first, on the top select services. Now find IoT code, right click and then open link in a new tab. Here on the left hand side in the navigation pane, choose act. Here, select Create a rule. Now giving a name to the rule. My ESP 32 underscore lambda underscore rule description.
This rule will send the sensor data to AWS lambda rule query statement. Ensure that you are using the latest version of SQL. Here we will give select attribute is star from the topic filter will be my sp 32 slash maker dummy data. And here we will not give any conditions. Don't forget to add single quotes for the topic filter, we will send the entire sensor data to lamda in AWS lambda we will check the data based on temperature values. Next set actions select Add action here select Send a message to lambda function and then configure action.
Now selecting the lambda function that we created previously, and then add action, the action has been successfully added. The IoT rule is ready. Now verify and select Create rule. The rule has been created successfully open lamda now refresh the page and here you can see that the trigger has been automatically added. For now I will end this video here. In this video, we learned the following what is AWS lambda by Avi using AWS lambda, creating a lambda function, creating an IoT rule.
In the next video, we will send messages to Sq s. See you in the next video.