쉽고 안전한 AWS IoT 플랫폼 활용하기 이창수 솔루션즈 아키텍트
쉽고 안전한 AWS IoT플랫폼 활용하기
이창수솔루션즈아키텍트
헬스케어및생명과학
공공 및인프라 스마트홈 유통
생산, 물류, 공급사슬 농업 교육 자동차
사물과 클라우드의 연결은 전 산업분야의 화두
데이터 생성과 접근이 빠르게 변화하고 있습니다
사람이 생성한 데이터
산발적인 상호작용
세상에 대한 부분적인 시각
기계가 생성한 데이터
지속적인 상호작용
세상에 대한 전체적인 시각
vs
사물을 연결하기 위한 필요요건들
다양한 SDK 및도구
프로토콜 확장성
&
노이즈/신호
보안 & 관리 클라우드, 모바일 앱또는 분석 기반의
통합
C SDK
(Ideal for embedded OS)
JavaScript SDK
(Ideal for Embedded Linux Platforms)
Arduino Library
(Arduino Yun)
Mobile SDK
(Android and iOS)
Python SDK Java SDK
https://aws.amazon.com/blogs/iot/introducing-aws-iot-device-sdks-for-java-and-python/
AWS IoT Device SDK
https://aws.amazon.com/ko/tools/
Dragonboard 410c
(by Arrow)
Beaglebone Green
(by Seeed Studio)
Seeeduino Cloud
(by Seeed Studio)
Intel Edison
(by Seeed Studio)
MediaTek LinkIt One
(by Seeed Studio)
Broadcom BCM4343W
(by Avnet)
Marvell EasyConnect
(By Marvell)
Renesas RX63N
(by Micrium)
Microchip WCM
(by Microchip)
Ti Launchpad
(By Ti)
다수 플랫폼에서 공식 AWS IoT Start kit 제공
“하나 또는 수백억개의 사물을 안전하게 연결하여
어플리케이션과 사물간에 상호 작용할 수 있게 합니다”
AWS IoT
Amway IoT 사례
• 외부에서 장치조정
• 장치상태모니터링
• 필터상태확인
• 실내공기상태모니터링
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo
Connected Car
MQTT
Voice Control
Shadow변경
수집된 모든 데이터 저장
Live Data View
운전 패턴을 저장하고 분석함
Control Demo Car
MQTT overWebsockets
Connected Car는 이렇게 구성될 수 있습니다
Connected Car
Connected 트럭의 이동 경로 시각화 예제
IoTrule
IoTaction
Amazon Elasticsearch
Service
Topic
KibanaConnected 트럭
AWS IoT Blog - Archive AWS IoT Device Shadows in Amazon Elasticsearch Service https://aws.amazon.com/blogs/iot/archive-aws-iot-device-shadows-in-amazon-elasticsearch-service/
AWSIoT
목차
• AWS IoT 플랫폼 살펴보기
• 사물과 커뮤니케이션 (Device gateway)
• 인증 (Authentication)
• 정책을 통한 인가 (Authorization by Policy)
• 사물 레지스트리 (Registry)
• 룰 엔진 (Rule Engine)
• 디바이스 섀도 (Device Shadow)
AWS IoT 플랫폼
IoT 서비스 구현에 필요한 요소들• 메시지 브로커• 룰 엔진• 디바이스 섀도• 디바이스 등록
관리형 서비스• 설치 불필요• 자동 확장• 사전 프로비저닝 불필요• 가용역영에 걸친 이중화• 사용량에 기반한 과금
AWS IoT는 무엇을 해줄까요?
DEVICE SDK연결, 인증, 메시지 교환을
위한 클라이언트 라이브러리
DEVICE GATEWAYMQTT 및 HTTP를 이용한Thing과의 커뮤니케이션
인증인증서 기반의 상호인증 및
암호화
RULES ENGINE규칙 기반으로메시지 변환 및
AWS 서비스로 전달
AWS Services- - - - -
3P Services
SHADOWThing 상태를 영구 저장
(불안정한 연결을 대비해서 사용)
APPLICATIONS
AWS IoT API
REGISTRY디바이스의 Identity 관리
AWS IoT는 AWS 서비스로의 Front Door
Registry• Thing에 대한 Identity 생성• Thing의 Attribute와 Capability 같은
메타데이터 관리
Rules / Actions패턴에 일치하는 메시지에 대해서 다른 AWS서비스로 전송하거나 AWS IoT로Re-publish를 수행
Shadows• Thing의 상태와 동기화• 앱이나 디바이스가 Shadow에 접근하여
상태를 읽거나 변경함
{Thing Name,
Sensor Temp,
, GetTemp(),
Output LED}
Rules Engine
Shadow
Registry
Amazon S3,
AWS Lambda,
Amazon Kinesis,
Amazon
DynamoDB,
Amazon SNS
Mobile App
사물과 커뮤니케이션(Device Gateway)
DEVICE GATEWAYMQTT 및 HTTP를 이용한Things와의 커뮤니케이션
AWS IoT Device Gateway
표준 프로토콜 지원
수백만 디바이스와 앱이 MQTT 및 HTTP 1.1 프로토콜을 이용해서 연결됨
오래 연결된 상태에서 메시지를 주고 받을수 있는 강력한 Pub/Sub 브로커
디바이스나 App인 클라이언트는클라우드로부터 명령을 받고, 신호를제어할 수 있음
Secure by Default
X.509 인증서 및 TLS 1.2 상호인증을 통한안전한 연결
토픽 기반의Architecture
(lights/thing-2/color)
확장성이 높은Device Gateway
AWS IoT Device Gateway
MQTT
MQTT vs HTTPS:
• 93x faster throughput• 11.89x less battery to send• 170.9x less battery to receive• 50% less power to keep connected• 8x less network overhead
Source: http://stephendnicholas.com/archives/ 1217
• AWS IoT네이티브지원프로토콜
• Lightweight, 다수대다수 pub/sub
• Long-lived 커넥션
• Secure TCP/IP port 8883
Pub: sensors/temp/room1
Sub: sensors/temp/room1
MQTT
Sub이 Full path를 등록하면Full path로 전송된 메시지만 수신
이 토픽에 Pub된 모든 메시지는Topic을 등록한 모든 Sub이 수신
Pub: sensors/temp/room1
Sub: sensors/+/room1
MQTT
(+)는 Sub이 정확히 room1에대한 메시지만 수신
이 토픽에 Pub된 모든 메시지는Topic에 등록한 모든 Sub이 수신
Pub: sensors/temp/room1
해쉬(#)는 temp 센서의모든 room 메시지 수신
Sub: sensors/temp/#
MQTT 이 토픽에 Pub된 모든 메시지는Topic에 등록한 모든 Sub이 수신
AWS IoT Message Broker : 관리형서비스
확장성이 높은Device Gateway
수백만 디바이스가수십억 메시지를보낼 수 있음
SubscribersPublishers
인증 (Authentication)
AUTHENTICATIONAUTHORIZATION
Secure with mutual authentication and
encryption
인증상호 인증 및 암호화로
보안 강화
인증
사물의 위험
I’m a thing
- 안전한 통신 채널
- 익명 사용자
- 안전한 통신 채널
- 익명 사물?
사물의 인증
- 안전한 통신 채널
- 상호 자격 증명
- 안전한 통신 채널
- 익명 사용자
사물의 인증 : TLS 기반 상호 인증
X.509 Certificates
AWS IoT로 생성한 Certificates • Expired되지 않음• 각각의 Device (사물)에 고유한 Certificate 권장
타 CA(Certificate Authority)를 통해 서명된 Certificates (BYOC)• Symantec 혹은 Verisign과 같은 CA로부터 서명된 x.509 certificate 발급• AWS IoT에서 해당 x.509 certificate 등록• 서명된 x.509 certificate로 device의 certificate 발급• AWS IoT에서 해당 device certificate를 등록 (JITR로 자동화 가능)
https://aws.amazon.com/blogs/iot/just-in-time-registration-of-device-certificates-on-aws-iot/
Register your CA Cert with
AWS IoT
Sign device certs with your CAcert
$aws/events/certificates/ registered/<caCertificateID>
{"certificateId": "<certificateID>", "caCertificateId": "<caCertificateId>", "timestamp": "<timestamp>", "certificateStatus":"PENDING_ACTIVATION", "awsAccountId":“<awsAccountId>",
}
AWS IoT
MQTT Endpoint
AWS IoT Ruleinvokes AWS Lambda function
AWS Lambda function activates certificate & attaches policy
New certificate state set to PENDING_ACTIVATION
Just-in-Time Registration
정책을통한인가(Authorization by Policy)
+Certificate Policy
인증서 + 정책
AWS IoT Policies는 JSON 형태로 IAM policies와동일형태
{"Version": "2012-10-17","Statement": [{
"Effect": "Allow", "Action":["iot:Publish"],
"Resource": ["arn:aws:iot:us-east-1:123456789012:topic/foo/bar"]},{
"Effect": "Allow", "Action": ["iot:Connect"],
"Resource": ["*"]}]
}
http://docs.aws.amazon.com/iot/latest/developerguide/authorization.html
Policy Actions
iot:Publish
iot:Subscribe
iot:Recieve
iot:Connect
iot:UpdateThingShadow
iot:GetThingShadow
iot:DeleteThingShadow
정책 (Policy)
$ aws iot create-policy --policy-name <value>\\
--policy-document <JSON policy document>
$ aws iot attach-principle-policy \\
--policy-name <value> \\
--principal <certificate ARN>
정책 생성 후 인증서에 붙이기
"Effect": "Allow",
"Action": [
"iot:Publish"
],
"Resource": [
"arn:aws:iot:us-east-1:123456789012:topic/foo"
]
},
{
"Effect": "Deny",
"Action": [
”iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-east-1:123456789012:topic/bar"
]
topic/foo 토픽으로 메시지 배
포 허용
topic/bar 토픽
메시지 수신 불가
정책 예제
Device Policy
Truck 1 Allow to connect and publish
Truck 2 Allow to connect / publish /
subscribe
Truck 3 Allow to connect / publish
/subscribe / unsubscribe
정책 예제
사용자/서비스 리소스인증/인가
사물레지스트리 (Registry)
사물 레지스트리
REGISTRYIdentity and Management of
your things
사물 레지스트리
AWS IoT에 연결된 모든 디바이스는레지스트리에 등록
사물과 관련된 정적인 속성을 저장• 펌웨어 버젼• 시리얼 번호• 디바이스 유형• 디바이스 그룹• 디바이스 설명• 센서 설명
지원 및 유지보수 목적의 추가 속성• 설명서의 URL• 부품 번호
사물 레지스트리: 사물(thing) 생성 & 리스트
http://docs.aws.amazon.com/iot/latest/developerguide/thing-registry.html
$ aws iot create-thing --thing-name "MyLightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\",\”model\":\"123\"}}"{
"thingArn": "arn:aws:iot:eu-west-1:554625704737:thing/MyLightBulb", "thingName": "MyLightBulb"
}$ aws iot list-things{
"things": [{
"attributes": { "model": "123",
"wattage": "75"},"version": 1, "thingName": "MyLightBulb"
}]
}
$ aws iot list-things --attribute-name "wattage" --attribute-value “75"{
"things": [{
"thingTypeName": "StopLight", "attributes": {
"model": "123","wattage": "75"
},"version": 3, "thingName": "MyLightBulb"
},{
"thingTypeName": "LightBulb", "attributes": {
"model": "123","wattage": "75"
},"version": 1, "thingName": "MyRGBLight"
}]
}
http://docs.aws.amazon.com/iot/latest/developerguide/thing-registry.html
사물 레지스트리: 사물(thing) 검색
사물 레지스트리 : 타입
http://docs.aws.amazon.com/iot/latest/developerguide/thing-registry.html
aws iot create-thing-type --thing-type-name "LightBulb" \\--thing-type-properties "thingTypeDescription=light bulb type,searchableAttributes=wattage,model"
타입을 사용하면 같은 타입의 모든 사물에 대한구성 정보를 동일하게 설정할 수 있습니다.
룰엔진 (Rule Engine)
데이터에서 가치를 찾아내기 위해서
• 특정 기준에 대해서 메시지를 필터링
• 메시지 내용 변환
• 메시지 내용에 따른 반응
• 메시지를 다른 topic들로 옮기기
• 메시지를 다른 시스템들로 옮기기
• 트랜드 기반의 변화 예측
룰 엔진
간단하고 친숙한 문법을 사용
• SQL 문장으로 토픽 필터 정의
• (옵션) WHERE절 사용
• 향상된 JSON 지원
시그널:노이즈 비율을 개선하기 위한함수들
• String 변환 (정규식 지원)
• 수학 연산
• Context 기반의 지원 함수들
• 암호 지원
• UUID, Timestamp, rand, 등
SELECT * FROM ‘things/thing-2/color’
WHERE color = ‘red’
룰 엔진은 …
1. 직접 연동되는AWS Services
Rules Engine
Action
AWS
Lambda
Amazon
SNS
Amazon
SQS
Amazon
S3
Amazon
Kinesis
Amazon
DynamoDB Amazon RDS
Amazon
Redshift
Amazon Glacier
Amazon
EC2
3. 외부 Endpoints(Lambda 및 SNS를 통해서 연동)
룰 엔진 액션은 AWS IoT를외부 Endpoint들과 AWS서비스를 연결하는 역할을합니다.
2. 간접 연동되는 AWS서비스(Amazon Kinesis, AWS Lambda, Amazon S3 등을통해서 연동)
룰 엔진 액션
룰 엔진 액션과 연동되는 AWS 서비스
Lambda function 호출
S3 bucket에 객체를 저장
DynamoDB 테이블에insert 및 update
SNS topic 또는endpoint에 Publish
Kinesis stream에 Publish
Firehose에 Publish
AWS IoT로 Republish
Elasticsearch로 Publish
CloudWatchmetric 생성 또는 알람 변경
SQS queue에 쓰기
AWS
IoT SDK
ECOSYSTEM OF
SMART DEVICES
Amazon EMR
TIME TO INSIGHT
Amazon Machine Learning
AWS Lambda
AWS Kinesis Analytics
많은 데이터, 빠르게 인사이트 도출✓ 제품 경고, 임계치 모니터링✓ 중대한 사용자 이벤트 감지 및 통보
변경이 쉽고, 서버리스이고, 저렴한 실행 비용✓ 제품 추론 및 데이터 운영✓ 복잡한 이벤트 프로파일 및 비즈니스 로직
쉽게 머신러닝 모델 생성, 머신 러닝 툴들 제공✓ 예방 정비✓ 사용자 행동 분석
대용량 데이터, 유연한 분석 엔진✓ 패턴 이력에 대한 배치 분석✓ 전체적인 인사이트
디바이스 데이터 분석을 위한 서비스 선택은 …
HOT
WARM
COOL
COLD
디바이스섀도 (Device
Shadow)
THING SHADOWPersistent thing state
during intermittent
connections
SHADOW
Thing 상태를 영구 저장(불안정한 연결을 대비해서 사용)
APPLICATIONS
디바이스 섀도
Shadow
클라우드 상에 존재하는디바이스의 가상적 실체(Virtual representation)
디바이스 섀도
reported
state
desired
state
MQ
TT
보고된 현재 상태
변경하고자 하는 상태
Controller
디바이스 섀도
‘desired’ 상태
device 상태를 변경하고자 사용- JSON 페이로드를 통해 변경하고자 디바이스 상태로 변경 요청
‘reported’, ‘desired’, ‘delta’ 차이- 변경 요청되었으나 아직 변경 처리가 안되어 실제 현재 디바이스
상태값인 reported값과 다른 값이 delta 로 보임
디바이스 섀도 : deltaInitial state
Requested updated state
Combined state
Delta notification
$aws/things/myThingName/shadow/update
Thing의토픽경로에이어서shadow address 생성됨
디바이스 섀도 : 경로
• /update
• /update/accepted
• /update/rejected
• /get
• /get/accepted
• /get/rejected
• /delete
• /delete/accepted
• /delete/rejected
$aws/things/myThingName/shadow...
디바이스 섀도 : 커맨드 예
디바이스 섀도 브로드캐스트 패턴
Controller
{
"desired":
"brightness" : "50"
}
PUB: $aws/things/lightbulb/shadow/update
Brightness : 30
Brightness : 30
Brightness : 30
AWS IoT
Publish Message
Device
Shadow
SUB: $aws/things/lightbulb/shadow/update
Controller
{
"delta": {
"brightness" : ”50"
}
}Brightness : 30
Brightness : 30
Brightness : 30
AWS IoT
Receive Message
SUB: $aws/things/lightbulb/shadow/delta
Device
Shadow
디바이스 섀도 브로드캐스트 패턴뒤에 전구들의 전원이 꺼져 있어
반영이 안된 Brightness :30 상태이므로 delta 50
Controller
{
“Desired": {
"brightness" : “50"
}
}
Brightness : 50
Brightness: 50
Brightness : 50
AWS IoT
Publish Message
PUB: $aws/things/lightbulb/shadow/update
SUB: $aws/things/lightbulb/shadow/update/accepted
Device
Shadow
디바이스 섀도 브로드캐스트 패턴
감사합니다