Before you begin
Before you begin, prepare the weather station emulator and connect it to AWS IoT Core by completing this
Learning Path
. Note that this Learning Path also includes the rule created in the
Learning Path about Amazon DynamoDB for IoT applications running on Arm64
.
Create the rule
Start by creating the rule:
- Open AWS IoT Core, and look for Rules under Message routing:
- Click the Create rule button. This opens the Create rule view, in which you configure the rule:
- Use the Create rule view to configure the rule. Firstly, under the rule name, type: check_temperature. Then, click the Next button. This takes you to the Configure SQL statement, where you use the following SQL query:
SELECT temperature FROM 'Emulators/Weather/SensorReadings'
This query ensures that only temperature readings are sent to the AWS Lambda function.
Click the Next button.
This opens the Attach rule actions, where under Action 1, select Lambda. This activates additional controls (see figure below):
- Click the Create a Lambda function button. This opens another tab. Select Author from scratch, type SendNotification for the function name, select Node.js 20.x for the runtime, and arm64 for the architecture:
- Scroll down, and under the Execution role, select Create a new role from AWS policy templates. This activates additional controls, where you type sns-email-role for the Role name. Then, click the drop-down list Policy templates, and select Amazon SNS publish policy:
- Click the Create function button. This takes you to the AWS Lambda Console, which looks as shown below:
- Keep the AWS Lambda Console open in a separate tab and go back to the Create rule wizard. Select SendNotification from the Lambda function dropdown, and ensure that the Lambda function version points to $LATEST:
Click the Next button, and then the Create button.
Go back to AWS Lambda Console and refresh the page. You will now see that your function accepts the AWS IoT trigger:
This means that the AWS Lambda function you have just created has an input trigger set to AWS IoT. Specifically, the AWS Lambda function is invoked whenever a new message is sent to the ‘Emulators/Weather/SensorReadings’ topic.
You are now ready to implement and test the Lambda function.