AI/ML, AWS, Cloud Computing, Internet of Things (IoT)

3 Mins Read

Simple IoT Alert Notification Using AWS IoT Rule and SNS

Voiced by Amazon Polly

Overview

When we do automation in the industry or the field of smart agriculture, we will continuously monitor various parameters such as temperature, humidity, CO2, pressure, and so on. If a particular threshold exists, we will trigger the actuator based on the different parameters this will allow us to boost industrial production or control the climate in agricultural greenhouses.

Whenever some parameters threshold exceeds, we must notify the end users, in this blog we will look at how to include IoT alert notifications using an AWS IoT Rule and SNS. You can use the AWS IoT Rules Engine to describe how data sent to AWS IoT Core interact with AWS services. AWS IoT rules are made up of three parts: a SQL SELECT expression, a topic filtering, and a rule action. Data can be extracted from receiving MQTT messages using the SQL SELECT command. Amazon SNS allows you to deliver notifications to your consumers directly.

iotsns1

Freedom Month Sale — Upgrade Your Skills, Save Big!

  • Up to 80% OFF AWS Courses
  • Up to 30% OFF Microsoft Certs
Act Fast!

Creation of SNS Topic and Subscription

Before building an IoT rule, we must first construct an SNS topic and subscription to receive and deliver data to the endpoint specified in the subscription.

  1. Log into an AWS console, search SNS in the search bar, and navigate to the Amazon SNS service.
  2. In the Amazon SNS service, in the left corner, click topics, then choose create topic, select type as Standard, input the name IoT_alert leave the other options alone and click create topic. Just a matter of time IoT_alert Topic will be created.

iotsns2

3. In the Amazon SNS service console Choose IoT_alert, which is just before we created.

4. In the IoT_alert topic down below click subscription then click create subscription. In the protocol section select Email.

5. In the Endpoint section enter your email address abc1232323@gmail.com then click create subscription.

iotsns3

6. After creating the subscription, we must confirm with entered email id. So, log on to entered email address and in your inbox, we can see the mail from AWS, click on Confirm subscription link to subscribe to the topic.

iotsns4

Creation of IoT Rule

  1. Go to Amazon IoT Core, select Message Routing on the left side of the IoT core console, and then click Rules.
  2. Choose Create Rule, enter IoT_alert_rule as the Rule name, then click Next.
  3. Select SQL version as 2016-03-23, then enter SELECT * FROM ‘device/12/IoT_alert’ WHERE temperature > 30 on the SQL statement, then click Next.
  4. In the Rule actions section, select action as simple Notification Service (SNS), then select SNS topic as arn:aws:sns:us-east-1:XXXXXXXXX-IoT_alert which is created in the previous step.
  5. Choose RAW as the message format, then in the IAM role section, select the create role option, then enter IoT_alert_role and click create.
  6. Down below click next finally review and click create option, the IoT_alert_rule will be created.

iotsns5

Data Ingestion and Testing

  1. To ingest the IoT data to AWS IoT core navigate to the AWS IoT core and click MQTT test client choose a publish option and a topic option.
  2. Enter the topic name as device/12/IoT_alert and message payload as {“temperature”: 27,”humidity”: 60} and click publish, similarly publish the message with different values as {“temperature”:35,”humidity”:65}.
  3. The second message has a temperature is > 30 so the IoT rule will trigger the SNS to send an email to the subscribed endpoint. Log into the registered email id and we can see the AWS Notification message from the SNS.

iotsns6

Conclusion

This blog taught us how to leverage IoT Rules and SNS for real-time notification. This will be used in many IoT applications for alert notifications when a specific threshold exceeds the typical value. Not only email notifications we can also invoke the different mobile and web application APIs.

Freedom Month Sale — Discounts That Set You Free!

  • Up to 80% OFF AWS Courses
  • Up to 30% OFF Microsoft Certs
Act Fast!

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

FAQs

1. Will AWS IoT Rule support topic filtering?

ANS: – Yes, using IoT Rule we can select the necessary IoT topic.

2. What are the applications of Amazon SNS?

ANS: – Amazon SNS allows you to deliver notifications to your consumers directly. Amazon SNS sends SMS text messages to over 200 countries, mobile push alerts to Amazon, Apple, Android, and Microsoft devices, and email notifications.

WRITTEN BY Vasanth Kumar R

Vasanth Kumar R works as a Sr. Research Associate at CloudThat. He is highly focused and passionate about learning new cutting-edge technologies including Cloud Computing, AI/ML & IoT/IIOT. He has experience with AWS and Azure Cloud Services, Embedded Software, and IoT/IIOT Development, and also worked with various sensors and actuators as well as electrical panels for Greenhouse Automation.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!