API Gateway을 이용하여 할 수 있는 일은?
API Gateway을 통해 만들 수 있는 API 종류
REST API는 웹 상의 어떤 자원에 대한 처리를 위해서 다음 3가지 구성요소로 정의된다.
REST API 설계 기본 규칙
요청
GET /devices
응답모델
{
"things": [
{
"thingName": "string",
"thingArn": "string"
},
...
]
}
요청
GET /devices/{deviceId}
응답 모델
{
"state": {
"desired": {
"attribute1": integer2,
"attribute2": "string2",
...
"attributeN": boolean2
},
"reported": {
"attribute1": integer1,
"attribute2": "string1",
...
"attributeN": boolean1
},
"delta": {
"attribute3": integerX,
"attribute5": "stringY"
}
},
"metadata": {
"desired": {
"attribute1": {
"timestamp": timestamp
},
"attribute2": {
"timestamp": timestamp
},
...
"attributeN": {
"timestamp": timestamp
}
},
"reported": {
"attribute1": {
"timestamp": timestamp
},
"attribute2": {
"timestamp": timestamp
},
...
"attributeN": {
"timestamp": timestamp
}
}
},
"timestamp": timestamp,
"clientToken": "token",
"version": version
}
요청
PUT /devices/{deviceID}
body
{
"tags" : [
{
"attrName": "temperature",
"attrValue": "27.0"
},
{
"attrName": "LED",
"attrValue": "OFF"
}
]
}
응답모델
요청
GET /devices/{deviceId}/log?from=2019-11-20 11:12:10&to=2019-12-1 12:00:00
응답모델
{
"data":[
{
"time":timestamp,
"attribute1": integer3,
"attribute2": "string3",
...
},
...
]
}
AWS IoT 플랫폼에서는 원하는 프로그래밍 언어를 기반으로 AWS SDK를 사용하여 디바이스 섀도에 액세스 할 수 있습니다. 이 장에서는 Java용 AWS SDK를 사용하여 Device Shadow를 액세스하는 Lambda 함수를 정의하고, 이 Lambda 함수를 API Gateway와 통합하여 2절에서 정의한 REST API를 구축하는 방법을 설명합니다.
AWS SDK for Java를 프로젝트에서 사용하려면 pom.xml 파일에서 종속성으로 필요한 개별 모듈을 선언해야 합니다. 디바이스 섀도에 액세스 하기 위해서는 aws-java-sdk-iot를 종속성으로 선언해야 합니다.