Louie NRT Story

[AWS] IOT Core Lambda 본문

서버시스템

[AWS] IOT Core Lambda

hyeok0724.kim@gmail.com 2020. 1. 13. 09:33
반응형

Writed: 14 JAN 2020

 

순서

1. Lambda 만들기

2. 규칙 만들기

3. 테스트 하기

 

1. Lambda 만들기

1) 기존의 예제를 활용함

2) 코드를 다음과 같이 씀. 그리고 기존에 만든 SNS 를 통하여 구독자에게

    메일을 보낼 수 있도록 arn 주소를 기입해줌

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import print_function
  
import json
import boto3
  
print('Loading function')
  
def lambda_handler(event, context):
  
    # Parse the JSON message 
    eventText = json.dumps(event)
  
    # Print the parsed JSON message to the console. You can view this text in the Monitoring tab in the AWS Lambda console or in the Amazon CloudWatch Logs console.
    print('Received event: ', eventText)
  
    # Create an SNS client
    sns = boto3.client('sns')
  
    # Publish a message to the specified topic
    response = sns.publish (
      TopicArn = 'arn:aws:iam::123456789012:My_IoT_SNS_Topic',
      Message = eventText
    )
  
    print(response)
 
 

3) 기존에 만든 SNS의 arn은 아래에서 확인 할 수 있음

 

4) 테스트 결과를 알 수 있음

 

2. 규칙 만들기

3. Pub 테스트 하기

1) 주어진 Topic에 대해서 주제 게시

반응형

'서버시스템' 카테고리의 다른 글

[AWS] IoT Core -> Lambda -> DynamoDB (1)  (0) 2020.01.27
[AWS] API Gateway -> Lambda  (0) 2020.01.27
[AWS] IOT Core DynamoDB  (0) 2020.01.13
[AWS] IOT Core SNS 규칙  (0) 2020.01.11
[AWS] IOT Core Basic  (0) 2020.01.10
Comments