SlideShare a Scribd company logo
SNS is the key to good architecture and help builds a pluggable pattern that makes for easy extension of your
application down the road. This is critcal for IoT system design since in many cases you'll want not just
guranteed message delivery but guranteed actions on those messages.
For this lab we'll setup an SNS topic, route messages from AWS IoT to SNS and then use Lambda to process
those messages but we'll also loop in SQS. SQS is used to recover from a failure during lambda processing.
Let's setup a new SNS topic.
Log into the AWS Console.
Open the SNS dashboard and create a new topic, we'll call this "iotSNS".
Make a note of the ARN for this new topic.
Lab 2 - The SNS Hook
Step 1
Let's setup a new SQS queue.
Open the SQS dashboard and create a new queue, we'll call this "iotSQS".
Make a note of the ARN for this new queue.
Step 2
Subscribe the queue to the SNS topic created earlier. Right the queue and select "Subscribe Queue to
SNS topic".
At this point any messages coming into our SNS topic also get sent to the SQS queue. We are not sending
them to SQS directly from AWS IoT since we want SNS to be our primary entry point.
Step 3
Next we'll create a Lambda function to process our messages. The lambda function is not going to act on
incoming messages directly. Instead it will pull batches from the SQS queue. We do this so that incoming
messages are our trigger for message processing.
Open the AWS Lambda dashboard.
Create a new Lambda and use the sns-message blue print.
Your event source will be SNS and use the iotSNS topic.
We'll call our Lambda function, "iotLambda".
You can use the follow sample code to start your lambda function.
console.log('Loading our IoT function ...');
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
var message = event.Records[0].Sns.Message;
console.log('From SNS:', message);
context.succeed(message);
};
When prompted enable your event source now.
Note: If you want to test your lambda function you need to use the following code instead, this code isn't
waiting for a Record object. Again, this is only for testing the lambda -> cloudwatch function.
JavaScript
console.log('Loading our IoT function ...');
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
context.succeed(true);
};
Let's test what we have so far. We'll add a rule and action to our AWS IoT setup that will listen to all topics and
pass that message onto our SNS topic.
Open the AWS IoT dashboard and click Create Resource, select Rule.
Create a rule with the following values:
Name : "thingrule"
Attribute : "*"
Topic Filter : "iot"
Choose the SNS action.
For your SNS target select the iotSNS that we created earlier.
For your role name, either use an existing role with sufficient permissions to call SNS or follow the wizard
to create that for you.
Click Add Action and then Create.
Step 4
JavaScript
Modify your thingtest.js to look like the following, notice we added in our topic name (iot) and we're still just
posting some test data.
Step 5
var awsIot = require('aws-iot-device-sdk');
var device = awsIot.device({
"host": "data.iot.us-west-2.amazonaws.com",
"port": 8883,
"clientId": "1234",
"thingName": "thingtest",
"caPath": "./root-CA.cer",
"certPath": "./certificate.pem.crt",
"keyPath": "./private.pem.key",
"region": "us-west-2"
});
var message = {
val1: "Value 1",
val2: "Value 2",
val3: "Value 3",
message: "Test Message"
};
device.on('connect', function() {
console.log('Connected!');
setTimeout(function() {
device.publish('iot', JSON.stringify(message));
console.log('Pushed message to Topic...');
}, 2500);
});
Now lets run this
node thingtest.js
We'll want to go see if our message is now in SQS along with the logs for our Lambda function which should
have logged our test data.
Note: If you see messages in SQS but not in Lambda you didn't enable your event source in the Lambda
function.
Here you can see our data being logged so we can now move on to processing the Queue.
JavaScript
Bash
AWS IoT 핸즈온 워크샵 - 실습 2. SNS 연동과 Lambda로 메시지 처리하기 (김무현 솔루션즈 아키텍트)

More Related Content

PDF
AWS AutoScaling
PDF
Auto scaling using Amazon Web Services ( AWS )
PPTX
Aws ec2
PPTX
Building Serverless Microservices Using Serverless Framework on the Cloud
PPTX
PPTX
AWS Lambda
PDF
Azure Resource Manager (ARM) Templates
PDF
AWS Systems Manager
AWS AutoScaling
Auto scaling using Amazon Web Services ( AWS )
Aws ec2
Building Serverless Microservices Using Serverless Framework on the Cloud
AWS Lambda
Azure Resource Manager (ARM) Templates
AWS Systems Manager

What's hot (20)

PPTX
Aws Autoscaling
PPTX
AWS Lambda
PPTX
PPTX
An introduction to Serverless
PDF
TechnicalTerraformLandingZones121120229238.pdf
PPT
Auto Scaling on AWS
PPTX
Introduction to AWS VPC, Guidelines, and Best Practices
PPTX
Azure Network Security Groups (NSG)
PDF
AWS VPC, ELB, Route53 and CloudFront
PPTX
Cloud Security (AWS)
PDF
AWS Cloud economics
PDF
금융권을 위한 AWS Direct Connect 기반 하이브리드 구성 방법 - AWS Summit Seoul 2017
PPTX
AWS Lambda Tutorial For Beginners | What is AWS Lambda? | AWS Tutorial For Be...
PDF
Security on AWS :: 이경수 솔루션즈아키텍트
PPTX
AWS Cloud trail
PPTX
What is private cloud Explained
PDF
[AWS Builders] AWS상의 보안 위협 탐지 및 대응
PPTX
Amazon services ec2
PPTX
Amazon_SNS.pptx
Aws Autoscaling
AWS Lambda
An introduction to Serverless
TechnicalTerraformLandingZones121120229238.pdf
Auto Scaling on AWS
Introduction to AWS VPC, Guidelines, and Best Practices
Azure Network Security Groups (NSG)
AWS VPC, ELB, Route53 and CloudFront
Cloud Security (AWS)
AWS Cloud economics
금융권을 위한 AWS Direct Connect 기반 하이브리드 구성 방법 - AWS Summit Seoul 2017
AWS Lambda Tutorial For Beginners | What is AWS Lambda? | AWS Tutorial For Be...
Security on AWS :: 이경수 솔루션즈아키텍트
AWS Cloud trail
What is private cloud Explained
[AWS Builders] AWS상의 보안 위협 탐지 및 대응
Amazon services ec2
Amazon_SNS.pptx
Ad

Viewers also liked (20)

PDF
AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)
PDF
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
PDF
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
PDF
AWS CLOUD 2017 - 서울 리전 개설 1년, 고객 관점 모범 아키텍처 설계 전략 (양승도 솔루션즈 아키텍트)
PDF
AWS CLOUD 2017 - AWS 코어팀과 함께하는 고객 성공 전략 (황인철 상무 & 박성훈 테크니컬 어카운트 매니저 & 김소희 컨설턴트)
PDF
AWS IoT 핸즈온 워크샵 - 실습 3. AWS IoT Thing Shadow (김무현 솔루션즈 아키텍트)
PDF
Cross-regional Application Deplolyment on AWS - Channy Yun (JAWS Days 2017)
PDF
Partner ConneXions - AWS 파트너를 위한 re:Invent 신규 서비스 소개 (윤석찬 테크에반젤리스트)
PDF
AWS CLOUD 2017 - Amazon Aurora를 통한 고성능 데이터베이스 운용하기 (박선용 솔루션즈 아키텍트)
PDF
천만 사용자를 위한 AWS 아키텍처 보안 모범 사례 (윤석찬, 테크에반젤리스트)
PDF
Amazon 인공 지능(AI) 서비스 및 AWS 기반 딥러닝 활용 방법 - 윤석찬 (AWS, 테크에반젤리스트)
PDF
AWS CLOUD 2017 - AWS 가상 컴퓨팅 분야 혁신 서비스 (박철수 솔루션즈 아키텍트)
PDF
AWS CLOUD 2017 - AWS 클라우드 비용 최적화 전략 (오길재 테크니컬 어카운트 매니저 & 이범석 테크니컬 어카운트 매니저)
PDF
AWS CLOUD 2017 - Amazon Athena 및 Glue를 통한 빠른 데이터 질의 및 처리 기능 소개 (김상필 솔루션즈 아키텍트)
PDF
AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)
PDF
Gaming on AWS - 8. 서버 없이 게임 만들기 - Serverless Architecture
PDF
Amazed by aws 1st session
PDF
3등 :: Game Indie :: Gaming on AWS Hackathon 2016
PDF
AWSomeday SEOUL, 2015 by megazone
PDF
하둡 알아보기(Learn about Hadoop basic), NetApp FAS NFS Connector for Hadoop
AWS IoT 핸즈온 워크샵 - 실습 4. Device Failure 상황 처리하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
AWS CLOUD 2017 - 서울 리전 개설 1년, 고객 관점 모범 아키텍처 설계 전략 (양승도 솔루션즈 아키텍트)
AWS CLOUD 2017 - AWS 코어팀과 함께하는 고객 성공 전략 (황인철 상무 & 박성훈 테크니컬 어카운트 매니저 & 김소희 컨설턴트)
AWS IoT 핸즈온 워크샵 - 실습 3. AWS IoT Thing Shadow (김무현 솔루션즈 아키텍트)
Cross-regional Application Deplolyment on AWS - Channy Yun (JAWS Days 2017)
Partner ConneXions - AWS 파트너를 위한 re:Invent 신규 서비스 소개 (윤석찬 테크에반젤리스트)
AWS CLOUD 2017 - Amazon Aurora를 통한 고성능 데이터베이스 운용하기 (박선용 솔루션즈 아키텍트)
천만 사용자를 위한 AWS 아키텍처 보안 모범 사례 (윤석찬, 테크에반젤리스트)
Amazon 인공 지능(AI) 서비스 및 AWS 기반 딥러닝 활용 방법 - 윤석찬 (AWS, 테크에반젤리스트)
AWS CLOUD 2017 - AWS 가상 컴퓨팅 분야 혁신 서비스 (박철수 솔루션즈 아키텍트)
AWS CLOUD 2017 - AWS 클라우드 비용 최적화 전략 (오길재 테크니컬 어카운트 매니저 & 이범석 테크니컬 어카운트 매니저)
AWS CLOUD 2017 - Amazon Athena 및 Glue를 통한 빠른 데이터 질의 및 처리 기능 소개 (김상필 솔루션즈 아키텍트)
AWS CLOUD 2017 - AWS 기반 하이브리드 클라우드 환경 구성 전략 (김용우 솔루션즈 아키텍트)
Gaming on AWS - 8. 서버 없이 게임 만들기 - Serverless Architecture
Amazed by aws 1st session
3등 :: Game Indie :: Gaming on AWS Hackathon 2016
AWSomeday SEOUL, 2015 by megazone
하둡 알아보기(Learn about Hadoop basic), NetApp FAS NFS Connector for Hadoop
Ad

Similar to AWS IoT 핸즈온 워크샵 - 실습 2. SNS 연동과 Lambda로 메시지 처리하기 (김무현 솔루션즈 아키텍트) (18)

PDF
NodeJS @ ACS
PPTX
Ovations AWS pop-up loft 2019 Technical presentation
PPTX
aws-iot-button-slideshow
PPTX
Alexa101 course slides
PDF
AWS Lambda Tutorial
PDF
AWS Lambda Presentation (Tech Talk DC)
PDF
AWS Lambda
PDF
Building a chatbot – step by step
PDF
10 Tips For Serverless Backends With NodeJS and AWS Lambda
PPTX
Introduction to Aws lambda and build first application | Namespace IT
PPTX
Unit 1 Express J for mean stack and mern
PDF
Hands-on with AWS IoT (November 2016)
PPTX
Containerless in the Cloud with AWS Lambda
PDF
AWS IoT Deep Dive
PDF
Build a mobile app serverless with AWS Lambda
PDF
Hands-on with AWS IoT
PDF
McrUmbMeetup 22 May 14: Umbraco and Amazon
PDF
An Overview of AWS IoT (November 2016)
NodeJS @ ACS
Ovations AWS pop-up loft 2019 Technical presentation
aws-iot-button-slideshow
Alexa101 course slides
AWS Lambda Tutorial
AWS Lambda Presentation (Tech Talk DC)
AWS Lambda
Building a chatbot – step by step
10 Tips For Serverless Backends With NodeJS and AWS Lambda
Introduction to Aws lambda and build first application | Namespace IT
Unit 1 Express J for mean stack and mern
Hands-on with AWS IoT (November 2016)
Containerless in the Cloud with AWS Lambda
AWS IoT Deep Dive
Build a mobile app serverless with AWS Lambda
Hands-on with AWS IoT
McrUmbMeetup 22 May 14: Umbraco and Amazon
An Overview of AWS IoT (November 2016)

More from Amazon Web Services Korea (20)

PDF
[D3T1S01] Gen AI를 위한 Amazon Aurora 활용 사례 방법
PDF
[D3T1S06] Neptune Analytics with Vector Similarity Search
PDF
[D3T1S03] Amazon DynamoDB design puzzlers
PDF
[D3T1S04] Aurora PostgreSQL performance monitoring and troubleshooting by use...
PDF
[D3T1S07] AWS S3 - 클라우드 환경에서 데이터베이스 보호하기
PDF
[D3T1S05] Aurora 혼합 구성 아키텍처를 사용하여 예상치 못한 트래픽 급증 대응하기
PDF
[D3T1S02] Aurora Limitless Database Introduction
PDF
[D3T2S01] Amazon Aurora MySQL 메이저 버전 업그레이드 및 Amazon B/G Deployments 실습
PDF
[D3T2S03] Data&AI Roadshow 2024 - Amazon DocumentDB 실습
PDF
AWS Modern Infra with Storage Roadshow 2023 - Day 2
PDF
AWS Modern Infra with Storage Roadshow 2023 - Day 1
PDF
사례로 알아보는 Database Migration Service : 데이터베이스 및 데이터 이관, 통합, 분리, 분석의 도구 - 발표자: ...
PDF
Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...
PDF
Amazon Elasticache - Fully managed, Redis & Memcached Compatible Service (Lev...
PDF
Internal Architecture of Amazon Aurora (Level 400) - 발표자: 정달영, APAC RDS Speci...
PDF
[Keynote] 슬기로운 AWS 데이터베이스 선택하기 - 발표자: 강민석, Korea Database SA Manager, WWSO, A...
PDF
Demystify Streaming on AWS - 발표자: 이종혁, Sr Analytics Specialist, WWSO, AWS :::...
PDF
Amazon EMR - Enhancements on Cost/Performance, Serverless - 발표자: 김기영, Sr Anal...
PDF
Amazon OpenSearch - Use Cases, Security/Observability, Serverless and Enhance...
PDF
Enabling Agility with Data Governance - 발표자: 김성연, Analytics Specialist, WWSO,...
[D3T1S01] Gen AI를 위한 Amazon Aurora 활용 사례 방법
[D3T1S06] Neptune Analytics with Vector Similarity Search
[D3T1S03] Amazon DynamoDB design puzzlers
[D3T1S04] Aurora PostgreSQL performance monitoring and troubleshooting by use...
[D3T1S07] AWS S3 - 클라우드 환경에서 데이터베이스 보호하기
[D3T1S05] Aurora 혼합 구성 아키텍처를 사용하여 예상치 못한 트래픽 급증 대응하기
[D3T1S02] Aurora Limitless Database Introduction
[D3T2S01] Amazon Aurora MySQL 메이저 버전 업그레이드 및 Amazon B/G Deployments 실습
[D3T2S03] Data&AI Roadshow 2024 - Amazon DocumentDB 실습
AWS Modern Infra with Storage Roadshow 2023 - Day 2
AWS Modern Infra with Storage Roadshow 2023 - Day 1
사례로 알아보는 Database Migration Service : 데이터베이스 및 데이터 이관, 통합, 분리, 분석의 도구 - 발표자: ...
Amazon DocumentDB - Architecture 및 Best Practice (Level 200) - 발표자: 장동훈, Sr. ...
Amazon Elasticache - Fully managed, Redis & Memcached Compatible Service (Lev...
Internal Architecture of Amazon Aurora (Level 400) - 발표자: 정달영, APAC RDS Speci...
[Keynote] 슬기로운 AWS 데이터베이스 선택하기 - 발표자: 강민석, Korea Database SA Manager, WWSO, A...
Demystify Streaming on AWS - 발표자: 이종혁, Sr Analytics Specialist, WWSO, AWS :::...
Amazon EMR - Enhancements on Cost/Performance, Serverless - 발표자: 김기영, Sr Anal...
Amazon OpenSearch - Use Cases, Security/Observability, Serverless and Enhance...
Enabling Agility with Data Governance - 발표자: 김성연, Analytics Specialist, WWSO,...

Recently uploaded (20)

PPTX
Exploration of Botanical Gardens of India
PDF
Hyderabad to Pune Flight – Complete Travel Guide.pdf
PPSX
Detian Transnational Waterfall, Chongzuo, Guangxi, CN. (中國 廣西崇左市 德天跨國瀑布).ppsx
PDF
Villa Oriente Porto Rotondo - Luxury Villlas Sardinia.pdf
PPTX
Quiz- Thursday.pptxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
PDF
Explore Luxemburry.eu, the ancient of lands in Europe
PDF
When is the best time to Visit Kailash Mansarovar.pdf
PDF
Step Into Lima’s Magic Explore Peru’s Historic Capital From Anywhere.pdf
PDF
Understanding Travel Insurance: Your Safety Net While Exploring the World
PPTX
MACRO-PERSPECTIVE-IN-HOSPITALITY-AND-TOURISM-MODULES.pptx
PDF
Best Things to Do in Orlando in 2025 Travel Guide.pdf
PDF
Introduction of Secrets of Mount Kailash.pdf
PDF
How to Choose the Best Tour Operators in Rajasthan – A Complete Guide.pdf
PDF
CruiseXplore 2025 Brochure – Your Guide to the Best Cruise Holidays from the ...
PDF
Delhi Agra Jaipur Tour Package 2025 – Travel with Rajasthan Tours India.pdf
PDF
Golden Triangle Tour A Complete Travel Guide.pdf
PDF
International Kailash Mansarovar Yatra, Visa, Permits, and Package.pdf
PDF
Travel Agents Email List for Effective Tourism and Hospitality Marketing.pdf
PPTX
Multimedia - Dinagsa Festival, Cadiz City
PDF
World Regional Geography 6th Edition Lydia Mihelic Pulsipher Download Test Ba...
Exploration of Botanical Gardens of India
Hyderabad to Pune Flight – Complete Travel Guide.pdf
Detian Transnational Waterfall, Chongzuo, Guangxi, CN. (中國 廣西崇左市 德天跨國瀑布).ppsx
Villa Oriente Porto Rotondo - Luxury Villlas Sardinia.pdf
Quiz- Thursday.pptxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Explore Luxemburry.eu, the ancient of lands in Europe
When is the best time to Visit Kailash Mansarovar.pdf
Step Into Lima’s Magic Explore Peru’s Historic Capital From Anywhere.pdf
Understanding Travel Insurance: Your Safety Net While Exploring the World
MACRO-PERSPECTIVE-IN-HOSPITALITY-AND-TOURISM-MODULES.pptx
Best Things to Do in Orlando in 2025 Travel Guide.pdf
Introduction of Secrets of Mount Kailash.pdf
How to Choose the Best Tour Operators in Rajasthan – A Complete Guide.pdf
CruiseXplore 2025 Brochure – Your Guide to the Best Cruise Holidays from the ...
Delhi Agra Jaipur Tour Package 2025 – Travel with Rajasthan Tours India.pdf
Golden Triangle Tour A Complete Travel Guide.pdf
International Kailash Mansarovar Yatra, Visa, Permits, and Package.pdf
Travel Agents Email List for Effective Tourism and Hospitality Marketing.pdf
Multimedia - Dinagsa Festival, Cadiz City
World Regional Geography 6th Edition Lydia Mihelic Pulsipher Download Test Ba...

AWS IoT 핸즈온 워크샵 - 실습 2. SNS 연동과 Lambda로 메시지 처리하기 (김무현 솔루션즈 아키텍트)

  • 1. SNS is the key to good architecture and help builds a pluggable pattern that makes for easy extension of your application down the road. This is critcal for IoT system design since in many cases you'll want not just guranteed message delivery but guranteed actions on those messages. For this lab we'll setup an SNS topic, route messages from AWS IoT to SNS and then use Lambda to process those messages but we'll also loop in SQS. SQS is used to recover from a failure during lambda processing. Let's setup a new SNS topic. Log into the AWS Console. Open the SNS dashboard and create a new topic, we'll call this "iotSNS". Make a note of the ARN for this new topic. Lab 2 - The SNS Hook Step 1
  • 2. Let's setup a new SQS queue. Open the SQS dashboard and create a new queue, we'll call this "iotSQS". Make a note of the ARN for this new queue. Step 2
  • 3. Subscribe the queue to the SNS topic created earlier. Right the queue and select "Subscribe Queue to SNS topic". At this point any messages coming into our SNS topic also get sent to the SQS queue. We are not sending them to SQS directly from AWS IoT since we want SNS to be our primary entry point. Step 3
  • 4. Next we'll create a Lambda function to process our messages. The lambda function is not going to act on incoming messages directly. Instead it will pull batches from the SQS queue. We do this so that incoming messages are our trigger for message processing. Open the AWS Lambda dashboard. Create a new Lambda and use the sns-message blue print. Your event source will be SNS and use the iotSNS topic. We'll call our Lambda function, "iotLambda". You can use the follow sample code to start your lambda function. console.log('Loading our IoT function ...'); exports.handler = function(event, context) { console.log('Received event:', JSON.stringify(event, null, 2)); var message = event.Records[0].Sns.Message; console.log('From SNS:', message); context.succeed(message); }; When prompted enable your event source now. Note: If you want to test your lambda function you need to use the following code instead, this code isn't waiting for a Record object. Again, this is only for testing the lambda -> cloudwatch function. JavaScript
  • 5. console.log('Loading our IoT function ...'); exports.handler = function(event, context) { console.log('Received event:', JSON.stringify(event, null, 2)); context.succeed(true); }; Let's test what we have so far. We'll add a rule and action to our AWS IoT setup that will listen to all topics and pass that message onto our SNS topic. Open the AWS IoT dashboard and click Create Resource, select Rule. Create a rule with the following values: Name : "thingrule" Attribute : "*" Topic Filter : "iot" Choose the SNS action. For your SNS target select the iotSNS that we created earlier. For your role name, either use an existing role with sufficient permissions to call SNS or follow the wizard to create that for you. Click Add Action and then Create. Step 4 JavaScript
  • 6. Modify your thingtest.js to look like the following, notice we added in our topic name (iot) and we're still just posting some test data. Step 5
  • 7. var awsIot = require('aws-iot-device-sdk'); var device = awsIot.device({ "host": "data.iot.us-west-2.amazonaws.com", "port": 8883, "clientId": "1234", "thingName": "thingtest", "caPath": "./root-CA.cer", "certPath": "./certificate.pem.crt", "keyPath": "./private.pem.key", "region": "us-west-2" }); var message = { val1: "Value 1", val2: "Value 2", val3: "Value 3", message: "Test Message" }; device.on('connect', function() { console.log('Connected!'); setTimeout(function() { device.publish('iot', JSON.stringify(message)); console.log('Pushed message to Topic...'); }, 2500); }); Now lets run this node thingtest.js We'll want to go see if our message is now in SQS along with the logs for our Lambda function which should have logged our test data. Note: If you see messages in SQS but not in Lambda you didn't enable your event source in the Lambda function. Here you can see our data being logged so we can now move on to processing the Queue. JavaScript Bash