Simple IoT Alert Notification Using AWS IoT Rule and SNS

November 17, 2022 | Comments(0) |

TABLE OF CONTENT

1. Overview
2. Creation of SNS Topic and Subscription
3. Creation of IoT Rule
4. Data Ingestion and Testing
5. Conclusion
6. About CloudThat
7. FAQs

 

Overview

A simple Notification Service is referred to as SNS. It is a web service that makes setting up, using, and sending cloud notifications simple. It gives programmers the incredibly flexible, affordable, and scalable capacity to post messages from one application and transmit them to other apps. It is a method of messaging. For example, when you use AutoScaling, an SNS service is triggered, sending you an email to let you know that “your EC2 instance is increasing.”

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

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.

About CloudThat

CloudThat is also the official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner and Microsoft gold partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best-in-industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

Drop a query if you have any questions regarding IoT Rule or SNS, and I will get back to you quickly.

To get started, go through our Consultancy page and Managed Services Package that is CloudThat’s offerings.

FAQs

  1. Will AWS IoT Rule support topic filtering?

A. Yes, using IoT Rule we can select the necessary IoT topic.

  1. What are the applications of Amazon SNS?

A. 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.


Leave a Reply