기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
로컬 섀도우와 상호작용
섀도우 IPC 서비스를 사용하여 기기의 로컬 섀도우와 상호 작용할 수 있습니다. 상호 작용하도록 선택한 장치는 코어 장치일 수도 있고 연결된 클라이언트 장치일 수도 있습니다.
이러한 IPC 작업을 사용하려면 섀도우 관리자 구성 요소를 사용자 지정 구성 요소의 종속 항목으로 포함시키십시오. 그런 다음 사용자 지정 구성 요소에서 IPC 작업을 사용하여 섀도우 관리자를 통해 장치의 로컬 섀도우와 상호 작용할 수 있습니다. 사용자 지정 구성 요소가 로컬 섀도우 상태의 변화에 반응하도록 하려면 게시/구독 IPC 서비스를 사용하여 섀도우 이벤트를 구독할 수도 있습니다. 게시/구독 서비스 사용에 대한 자세한 내용은 를 참조하십시오. 로컬 메시지 게시/구독
최소 SDK 버전
다음 표에는 로컬 섀도우와 상호 작용하는 데 사용해야 AWS IoT Device SDK 하는 의 최소 버전이 나와 있습니다.
권한 부여
사용자 지정 구성 요소에서 섀도우 IPC 서비스를 사용하려면 구성 요소가 섀도우와 상호 작용할 수 있도록 허용하는 권한 부여 정책을 정의해야 합니다. 권한 부여 정책 정의에 대한 자세한 내용은 을 참조하십시오구성 요소가 작업을 수행할 수 있도록 승인하십시오. IPC .
섀도우 상호 작용에 대한 권한 부여 정책에는 다음과 같은 속성이 있습니다.
IPC 서비스 식별자: aws.greengrass.ShadowManager
Operation |
설명 |
리소스 |
aws.greengrass#GetThingShadow
|
구성 요소가 사물의 그림자를 검색할 수 있도록 합니다.
|
다음 문자열 중 하나:
-
$aws/things/thingName /shadow/ , 클래식 디바이스 섀도우에 대한 액세스를 허용하려면
-
$aws/things/thingName /shadow/name/shadowName , 명명된 섀도우에 대한 액세스를 허용하려는 경우
-
* 모든 섀도우에 대한 액세스를 허용하기 위해서입니다.
|
aws.greengrass#UpdateThingShadow
|
컴포넌트가 사물의 섀도우를 업데이트할 수 있도록 합니다.
|
다음 문자열 중 하나:
-
$aws/things/thingName /shadow/ , 클래식 디바이스 섀도우에 대한 액세스를 허용하려면
-
$aws/things/thingName /shadow/name/shadowName , 명명된 섀도우에 대한 액세스를 허용하려는 경우
-
* 모든 섀도우에 대한 액세스를 허용하기 위해서입니다.
|
aws.greengrass#DeleteThingShadow
|
컴포넌트가 사물의 그림자를 삭제할 수 있도록 합니다.
|
다음 문자열 중 하나:
-
$aws/things/thingName /shadow/ , 클래식 디바이스 섀도우에 대한 액세스를 허용하려면
-
$aws/things/thingName /shadow/name/shadowName , 명명된 섀도우에 대한 액세스 허용하기
-
* , 모든 섀도우에 대한 액세스를 허용하려면
|
aws.greengrass#ListNamedShadowsForThing
|
컴포넌트가 사물에 대해 명명된 섀도우 목록을 검색할 수 있도록 합니다.
|
사물에 액세스하여 섀도우를 나열할 수 있는 사물 이름 문자열입니다.
모든 항목에 대한 액세스를 허용하는 * 데 사용합니다.
|
IPC 서비스 식별자: aws.greengrass.ipc.pubsub
Operation |
설명 |
리소스 |
aws.greengrass#SubscribeToTopic
|
구성 요소가 지정한 주제에 대한 메시지를 구독할 수 있도록 합니다.
|
다음 주제 문자열 중 하나:
-
shadowTopicPrefix /get/accepted
-
shadowTopicPrefix /get/rejected
-
shadowTopicPrefix /delete/accepted
-
shadowTopicPrefix /delete/rejected
-
shadowTopicPrefix /update/accepted
-
shadowTopicPrefix /update/delta
-
shadowTopicPrefix /update/rejected
주제 접두사의 값은 섀도우 유형에 shadowTopicPrefix 따라 달라집니다.
모든 주제에 대한 액세스를 허용하는 * 데 사용합니다.
Greengrass nucleus v2.6.0 이상에서는 MQTT 주제 와일드카드 (및) 가 포함된 주제를 구독할 수 있습니다. # + 이 주제 문자열은 MQTT 주제 와일드카드를 리터럴 문자로 지원합니다. 예를 들어 구성 요소의 권한 부여 정책이 액세스 권한을 부여하면 구성 요소가 구독할 수는 있지만 구독할 test/topic/# 수는 없습니다. test/topic/# test/topic/filter
|
로컬 섀도우 권한 부여 정책의 레시피 변수
v2.6.0 이상의 Greengrass 핵을 사용하고 Greengrass 핵의 interpolateComponentConfiguration구성 옵션을 로 설정하면 권한 부여 정책에서 레시피 변수를 사용할 수 true 있습니다. {iot:thingName} 이 기능을 사용하면 각 코어 디바이스가 자체 섀도우에만 액세스할 수 있도록 코어 디바이스 그룹에 대해 단일 권한 부여 정책을 구성할 수 있습니다. 예를 들어 섀도우 IPC 작업을 위해 구성 요소가 다음 리소스에 액세스하도록 허용할 수 있습니다.
$aws/things/{iot:thingName}/shadow/
권한 부여 정책 예제
다음 권한 부여 정책 예제를 참조하여 구성 요소에 대한 권한 부여 정책을 구성할 수 있습니다.
예: 코어 디바이스 그룹이 로컬 섀도우와 상호 작용하도록 허용
다음 예제 권한 부여 정책은 구성 요소가 com.example.MyShadowInteractionComponent
클래식 디바이스 섀도 및 구성 요소를 실행하는 코어 디바이스의 명명된 myNamedShadow
섀도우와 상호 작용할 수 있도록 허용합니다. 또한 이 정책을 통해 이 구성 요소는 이러한 섀도우에 대한 로컬 주제에 대한 메시지를 수신할 수 있습니다.
- JSON
-
{
"accessControl": {
"aws.greengrass.ShadowManager": {
"com.example.MyShadowInteractionComponent:shadow:1": {
"policyDescription": "Allows access to shadows",
"operations": [
"aws.greengrass#GetThingShadow",
"aws.greengrass#UpdateThingShadow",
"aws.greengrass#DeleteThingShadow"
],
"resources": [
"$aws/things/{iot:thingName}/shadow",
"$aws/things/{iot:thingName}/shadow/name/myNamedShadow"
]
},
"com.example.MyShadowInteractionComponent:shadow:2": {
"policyDescription": "Allows access to things with shadows",
"operations": [
"aws.greengrass#ListNamedShadowsForThing"
],
"resources": [
"{iot:thingName}"
]
}
},
"aws.greengrass.ipc.pubsub": {
"com.example.MyShadowInteractionComponent:pubsub:1": {
"policyDescription": "Allows access to shadow pubsub topics",
"operations": [
"aws.greengrass#SubscribeToTopic"
],
"resources": [
"$aws/things/{iot:thingName}/shadow/get/accepted",
"$aws/things/{iot:thingName}/shadow/name/myNamedShadow/get/accepted"
]
}
}
}
}
- YAML
-
accessControl:
aws.greengrass.ShadowManager:
'com.example.MyShadowInteractionComponent:shadow:1':
policyDescription: 'Allows access to shadows'
operations:
- 'aws.greengrass#GetThingShadow'
- 'aws.greengrass#UpdateThingShadow'
- 'aws.greengrass#DeleteThingShadow'
resources:
- $aws/things/{iot:thingName}/shadow
- $aws/things/{iot:thingName}/shadow/name/myNamedShadow
'com.example.MyShadowInteractionComponent:shadow:2':
policyDescription: 'Allows access to things with shadows'
operations:
- 'aws.greengrass#ListNamedShadowsForThing'
resources:
- '{iot:thingName}'
aws.greengrass.ipc.pubsub:
'com.example.MyShadowInteractionComponent:pubsub:1':
policyDescription: 'Allows access to shadow pubsub topics'
operations:
- 'aws.greengrass#SubscribeToTopic'
resources:
- $aws/things/{iot:thingName}/shadow/get/accepted
- $aws/things/{iot:thingName}/shadow/name/myNamedShadow/get/accepted
예: 핵심 장치 그룹이 클라이언트 장치 섀도우와 상호 작용하도록 허용
다음 예제 권한 부여 정책은 구성 요소가 com.example.MyShadowInteractionComponent
이름이 로 시작하는 클라이언트 장치의 모든 디바이스 섀도우와 상호 작용할 수 있도록 허용합니다. MyClientDevice
- JSON
-
{
"accessControl": {
"aws.greengrass.ShadowManager": {
"com.example.MyShadowInteractionComponent:shadow:1": {
"policyDescription": "Allows access to shadows",
"operations": [
"aws.greengrass#GetThingShadow",
"aws.greengrass#UpdateThingShadow",
"aws.greengrass#DeleteThingShadow"
],
"resources": [
"$aws/things/MyClientDevice*/shadow",
"$aws/things/MyClientDevice*/shadow/name/*"
]
},
"com.example.MyShadowInteractionComponent:shadow:2": {
"policyDescription": "Allows access to things with shadows",
"operations": [
"aws.greengrass#ListNamedShadowsForThing"
],
"resources": [
"MyClientDevice*"
]
}
}
}
}
- YAML
-
accessControl:
aws.greengrass.ShadowManager:
'com.example.MyShadowInteractionComponent:shadow:1':
policyDescription: 'Allows access to shadows'
operations:
- 'aws.greengrass#GetThingShadow'
- 'aws.greengrass#UpdateThingShadow'
- 'aws.greengrass#DeleteThingShadow'
resources:
- $aws/things/MyClientDevice*/shadow
- $aws/things/MyClientDevice*/shadow/name/*
'com.example.MyShadowInteractionComponent:shadow:2':
policyDescription: 'Allows access to things with shadows'
operations:
- 'aws.greengrass#ListNamedShadowsForThing'
resources:
- MyClientDevice*
예: 단일 코어 기기가 로컬 섀도우와 상호 작용하도록 허용
다음 예제 권한 부여 정책은 구성 요소가 com.example.MyShadowInteractionComponent
클래식 장치 섀도 및 장치의 명명된 섀도우와 상호 작용할 수 myNamedShadow
있도록 허용합니다MyThingName
. 또한 이 정책을 통해 이 구성 요소는 이러한 섀도우에 대한 로컬 주제에 대한 메시지를 수신할 수 있습니다.
- JSON
-
{
"accessControl": {
"aws.greengrass.ShadowManager": {
"com.example.MyShadowInteractionComponent:shadow:1": {
"policyDescription": "Allows access to shadows",
"operations": [
"aws.greengrass#GetThingShadow",
"aws.greengrass#UpdateThingShadow",
"aws.greengrass#DeleteThingShadow"
],
"resources": [
"$aws/things/MyThingName/shadow",
"$aws/things/MyThingName/shadow/name/myNamedShadow"
]
},
"com.example.MyShadowInteractionComponent:shadow:2": {
"policyDescription": "Allows access to things with shadows",
"operations": [
"aws.greengrass#ListNamedShadowsForThing"
],
"resources": [
"MyThingName"
]
}
},
"aws.greengrass.ipc.pubsub": {
"com.example.MyShadowInteractionComponent:pubsub:1": {
"policyDescription": "Allows access to shadow pubsub topics",
"operations": [
"aws.greengrass#SubscribeToTopic"
],
"resources": [
"$aws/things/MyThingName/shadow/get/accepted",
"$aws/things/MyThingName/shadow/name/myNamedShadow/get/accepted"
]
}
}
}
}
- YAML
-
accessControl:
aws.greengrass.ShadowManager:
'com.example.MyShadowInteractionComponent:shadow:1':
policyDescription: 'Allows access to shadows'
operations:
- 'aws.greengrass#GetThingShadow'
- 'aws.greengrass#UpdateThingShadow'
- 'aws.greengrass#DeleteThingShadow'
resources:
- $aws/things/MyThingName/shadow
- $aws/things/MyThingName/shadow/name/myNamedShadow
'com.example.MyShadowInteractionComponent:shadow:2':
policyDescription: 'Allows access to things with shadows'
operations:
- 'aws.greengrass#ListNamedShadowsForThing'
resources:
- MyThingName
aws.greengrass.ipc.pubsub:
'com.example.MyShadowInteractionComponent:pubsub:1':
policyDescription: 'Allows access to shadow pubsub topics'
operations:
- 'aws.greengrass#SubscribeToTopic'
resources:
- $aws/things/MyThingName/shadow/get/accepted
- $aws/things/MyThingName/shadow/name/myNamedShadow/get/accepted
예: 코어 디바이스 그룹이 로컬 섀도우 상태 변경에 반응하도록 허용
다음 예제 액세스 제어 정책을 사용하면 사용자 com.example.MyShadowReactiveComponent
지정이 클래식 디바이스 섀도와 해당 구성 요소를 실행하는 각 코어 디바이스의 명명된 myNamedShadow
섀도우에 대한 /update/delta
주제에 대한 메시지를 받을 수 있습니다.
- JSON
-
{
"accessControl": {
"aws.greengrass.ipc.pubsub": {
"com.example.MyShadowReactiveComponent:pubsub:1": {
"policyDescription": "Allows access to shadow pubsub topics",
"operations": [
"aws.greengrass#SubscribeToTopic"
],
"resources": [
"$aws/things/{iot:thingName}/shadow/update/delta",
"$aws/things/{iot:thingName}/shadow/name/myNamedShadow/update/delta"
]
}
}
}
}
- YAML
-
accessControl:
aws.greengrass.ipc.pubsub:
"com.example.MyShadowReactiveComponent:pubsub:1":
policyDescription: Allows access to shadow pubsub topics
operations:
- 'aws.greengrass#SubscribeToTopic'
resources:
- $aws/things/{iot:thingName}/shadow/update/delta
- $aws/things/{iot:thingName}/shadow/name/myNamedShadow/update/delta
예: 단일 코어 장치가 로컬 섀도우 상태 변경에 반응하도록 허용
다음 예제 액세스 제어 정책을 사용하면 사용자 com.example.MyShadowReactiveComponent
지정이 클래식 장치 섀도와 장치의 명명된 섀도우에 대한 /update/delta
주제에 myNamedShadow
대한 메시지를 받을 수 MyThingName
있습니다.
- JSON
-
{
"accessControl": {
"aws.greengrass.ipc.pubsub": {
"com.example.MyShadowReactiveComponent:pubsub:1": {
"policyDescription": "Allows access to shadow pubsub topics",
"operations": [
"aws.greengrass#SubscribeToTopic"
],
"resources": [
"$aws/things/MyThingName/shadow/update/delta",
"$aws/things/MyThingName/shadow/name/myNamedShadow/update/delta"
]
}
}
}
}
- YAML
-
accessControl:
aws.greengrass.ipc.pubsub:
"com.example.MyShadowReactiveComponent:pubsub:1":
policyDescription: Allows access to shadow pubsub topics
operations:
- 'aws.greengrass#SubscribeToTopic'
resources:
- $aws/things/MyThingName/shadow/update/delta
- $aws/things/MyThingName/shadow/name/myNamedShadow/update/delta
GetThingShadow
지정된 사물에 대한 섀도우를 가져오십시오.
요청
이 작업의 요청에는 다음과 같은 매개변수가 있습니다.
thingName
(Python:thing_name
)
-
사물의 이름입니다.
유형: string
shadowName
(Python:shadow_name
)
-
섀도우의 이름입니다. 사물의 클래식 섀도우를 지정하려면 이 매개변수를 빈 문자열 (""
) 으로 설정하십시오.
이 AWS IoT Greengrass 서비스는 AWSManagedGreengrassV2Deployment
명명된 섀도우를 사용하여 개별 코어 장치를 대상으로 하는 배포를 관리합니다. 이 이름이 지정된 섀도우는 서비스에서 사용하도록 예약되어 있습니다AWS IoT Greengrass. 이름이 지정된 이 섀도우를 업데이트하거나 삭제하지 마십시오.
유형: string
응답
이 작업의 응답에는 다음 정보가 포함됩니다.
payload
-
블럽 형태의 응답 상태 문서.
다음 정보가 object
포함된 유형:
state
-
상태 정보.
이 개체에는 다음 정보가 들어 있습니다.
desired
-
장치에서 업데이트하도록 요청된 상태 속성 및 값.
유형: map
키-값 쌍
reported
-
기기에서 보고한 상태 속성 및 값.
유형: map
키-값 쌍
delta
-
원하는 상태 속성과 보고된 상태 속성 및 값 간의 차이 이 속성은 desired
및 reported
상태가 다른 경우에만 나타납니다.
유형: map
키-값 쌍
metadata
-
desired
및 reported
섹션의 각 속성에 대한 타임스탬프를 통해 상태가 업데이트된 시기를 확인할 수 있습니다.
유형: string
timestamp
-
응답이 생성된 에포크 날짜 및 시간.
유형: integer
clientToken
(Python:clientToken
)
-
요청과 해당 응답을 일치시키는 데 사용되는 토큰
유형: string
version
-
로컬 섀도우 문서의 버전.
유형: integer
Errors
이 작업을 수행하면 다음 오류가 반환될 수 있습니다.
InvalidArgumentsError
-
로컬 섀도우 서비스가 요청 파라미터를 검증할 수 없습니다. 요청에 잘못된 형식의 JSON이나 지원되지 않는 문자가 포함된 경우 이 문제가 발생할 수 있습니다.
ResourceNotFoundError
-
요청된 로컬 섀도우 문서를 찾을 수 없습니다.
ServiceError
-
내부 서비스 오류가 발생했거나 IPC 서비스에 대한 요청 수가 섀도우 관리자 구성 요소의 maxLocalRequestsPerSecondPerThing
및 maxTotalLocalRequestsRate
구성 매개변수에 지정된 제한을 초과했습니다.
UnauthorizedError
-
구성 요소의 권한 부여 정책에는 이 작업에 필요한 권한이 포함되어 있지 않습니다.
예제
다음 예제는 사용자 지정 구성 요소 코드에서 이 작업을 호출하는 방법을 보여줍니다.
- Java (IPC client V1)
-
예: 사물 그림자 가져오기
package com.aws.greengrass.docs.samples.ipc;
import com.aws.greengrass.docs.samples.ipc.util.IPCUtils;
import software.amazon.awssdk.aws.greengrass.GetThingShadowResponseHandler;
import software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient;
import software.amazon.awssdk.aws.greengrass.model.GetThingShadowRequest;
import software.amazon.awssdk.aws.greengrass.model.GetThingShadowResponse;
import software.amazon.awssdk.aws.greengrass.model.ResourceNotFoundError;
import software.amazon.awssdk.aws.greengrass.model.UnauthorizedError;
import software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class GetThingShadow {
public static final int TIMEOUT_SECONDS = 10;
public static void main(String[] args) {
// Use the current core device's name if thing name isn't set.
String thingName = args[0].isEmpty() ? System.getenv("AWS_IOT_THING_NAME") : args[0];
String shadowName = args[1];
try (EventStreamRPCConnection eventStreamRPCConnection =
IPCUtils.getEventStreamRpcConnection()) {
GreengrassCoreIPCClient ipcClient =
new GreengrassCoreIPCClient(eventStreamRPCConnection);
GetThingShadowResponseHandler responseHandler =
GetThingShadow.getThingShadow(ipcClient, thingName, shadowName);
CompletableFuture<GetThingShadowResponse> futureResponse =
responseHandler.getResponse();
try {
GetThingShadowResponse response = futureResponse.get(TIMEOUT_SECONDS,
TimeUnit.SECONDS);
String shadowPayload = new String(response.getPayload(), StandardCharsets.UTF_8);
System.out.printf("Successfully got shadow %s/%s: %s%n", thingName, shadowName,
shadowPayload);
} catch (TimeoutException e) {
System.err.printf("Timeout occurred while getting shadow: %s/%s%n", thingName,
shadowName);
} catch (ExecutionException e) {
if (e.getCause() instanceof UnauthorizedError) {
System.err.printf("Unauthorized error while getting shadow: %s/%s%n",
thingName, shadowName);
} else if (e.getCause() instanceof ResourceNotFoundError) {
System.err.printf("Unable to find shadow to get: %s/%s%n", thingName,
shadowName);
} else {
throw e;
}
}
} catch (InterruptedException e) {
System.out.println("IPC interrupted.");
} catch (ExecutionException e) {
System.err.println("Exception occurred when using IPC.");
e.printStackTrace();
System.exit(1);
}
}
public static GetThingShadowResponseHandler getThingShadow(GreengrassCoreIPCClient greengrassCoreIPCClient, String thingName, String shadowName) {
GetThingShadowRequest getThingShadowRequest = new GetThingShadowRequest();
getThingShadowRequest.setThingName(thingName);
getThingShadowRequest.setShadowName(shadowName);
return greengrassCoreIPCClient.getThingShadow(getThingShadowRequest, Optional.empty());
}
}
- Python (IPC client V1)
-
예: 사물 섀도우 가져오기
import awsiot.greengrasscoreipc
import awsiot.greengrasscoreipc.client as client
from awsiot.greengrasscoreipc.model import GetThingShadowRequest
TIMEOUT = 10
def sample_get_thing_shadow_request(thingName, shadowName):
try:
# set up IPC client to connect to the IPC server
ipc_client = awsiot.greengrasscoreipc.connect()
# create the GetThingShadow request
get_thing_shadow_request = GetThingShadowRequest()
get_thing_shadow_request.thing_name = thingName
get_thing_shadow_request.shadow_name = shadowName
# retrieve the GetThingShadow response after sending the request to the IPC server
op = ipc_client.new_get_thing_shadow()
op.activate(get_thing_shadow_request)
fut = op.get_response()
result = fut.result(TIMEOUT)
return result.payload
except InvalidArgumentsError as e:
# add error handling
...
# except ResourceNotFoundError | UnauthorizedError | ServiceError
- JavaScript
-
예: 사물 섀도우 가져오기
import {
GetThingShadowRequest
} from 'aws-iot-device-sdk-v2/dist/greengrasscoreipc/model';
import * as greengrasscoreipc from 'aws-iot-device-sdk-v2/dist/greengrasscoreipc';
class GetThingShadow {
private ipcClient: greengrasscoreipc.Client;
private thingName: string;
private shadowName: string;
constructor() {
// Define args parameters here
this.thingName = "<define_your_own_thingName>";
this.shadowName = "<define_your_own_shadowName>";
this.bootstrap();
}
async bootstrap() {
try {
this.ipcClient = await getIpcClient();
} catch (err) {
// parse the error depending on your use cases
throw err
}
try {
await this.handleGetThingShadowOperation(this.thingName,
this.shadowName);
} catch (err) {
// parse the error depending on your use cases
throw err
}
}
async handleGetThingShadowOperation(
thingName: string,
shadowName: string
) {
const request: GetThingShadowRequest = {
thingName: thingName,
shadowName: shadowName
};
const response = await this.ipcClient.getThingShadow(request);
}
}
export async function getIpcClient() {
try {
const ipcClient = greengrasscoreipc.createClient();
await ipcClient.connect()
.catch(error => {
// parse the error depending on your use cases
throw error;
});
return ipcClient
} catch (err) {
// parse the error depending on your use caseså
throw err
}
}
const startScript = new GetThingShadow();
UpdateThingShadow
지정된 사물의 섀도우를 업데이트하십시오. 섀도우가 없는 경우 섀도우가 생성됩니다.
요청
이 작업의 요청에는 다음과 같은 매개변수가 있습니다.
thingName
(Python:thing_name
)
-
사물의 이름입니다.
유형: string
shadowName
(Python:shadow_name
)
-
섀도우의 이름입니다. 사물의 클래식 섀도우를 지정하려면 이 매개변수를 빈 문자열 (""
) 으로 설정하십시오.
이 AWS IoT Greengrass 서비스는 AWSManagedGreengrassV2Deployment
명명된 섀도우를 사용하여 개별 코어 장치를 대상으로 하는 배포를 관리합니다. 이 이름이 지정된 섀도우는 서비스에서 사용하도록 예약되어 있습니다AWS IoT Greengrass. 이름이 지정된 이 섀도우를 업데이트하거나 삭제하지 마십시오.
유형: string
payload
-
Blob 형태의 요청 상태 문서.
다음 정보가 object
포함된 유형:
state
-
업데이트할 상태 정보. 이 IPC 작업은 지정된 필드에만 영향을 줍니다.
이 객체에는 다음 정보가 들어 있습니다. 일반적으로 동일한 요청에서 desired
속성과 속성 중 하나를 사용하지만 둘 다 사용하지는 않습니다. reported
desired
-
기기에서 업데이트하도록 요청된 상태 속성 및 값
유형: map
키-값 쌍
reported
-
기기에서 보고한 상태 속성 및 값.
유형: map
키-값 쌍
clientToken
(Python:client_token
)
-
(선택 사항) 클라이언트 토큰의 요청과 해당 응답을 일치시키는 데 사용되는 토큰입니다.
유형: string
version
-
(선택 사항) 업데이트할 로컬 섀도우 문서의 버전. 섀도우 서비스는 지정된 버전이 최신 버전과 일치하는 경우에만 업데이트를 처리합니다.
유형: integer
응답
이 작업의 응답에는 다음 정보가 포함됩니다.
payload
-
블럽 형태의 응답 상태 문서.
다음 정보가 object
포함된 유형:
state
-
상태 정보.
이 개체에는 다음 정보가 들어 있습니다.
desired
-
장치에서 업데이트하도록 요청된 상태 속성 및 값.
유형: map
키-값 쌍
reported
-
기기에서 보고한 상태 속성 및 값.
유형: map
키-값 쌍
delta
-
기기에서 보고한 상태 속성 및 값.
유형: map
키-값 쌍
metadata
-
desired
및 reported
섹션의 각 속성에 대한 타임스탬프를 통해 상태가 업데이트된 시기를 확인할 수 있습니다.
유형: string
timestamp
-
응답이 생성된 에포크 날짜 및 시간.
유형: integer
clientToken
(Python:client_token
)
-
요청과 해당 응답을 일치시키는 데 사용되는 토큰입니다.
유형: string
version
-
업데이트가 완료된 후의 로컬 섀도우 문서 버전입니다.
유형: integer
Errors
이 작업을 수행하면 다음 오류가 반환될 수 있습니다.
ConflictError
-
업데이트 작업 중에 로컬 섀도우 서비스에서 버전 충돌이 발생했습니다. 이 문제는 요청 페이로드의 버전이 사용 가능한 최신 로컬 섀도 문서의 버전과 일치하지 않을 때 발생합니다.
InvalidArgumentsError
-
로컬 섀도우 서비스는 요청 파라미터를 검증할 수 없습니다. 요청에 잘못된 형식의 JSON이나 지원되지 않는 문자가 포함된 경우 이 문제가 발생할 수 있습니다.
payload
Valid에는 다음과 같은 속성이 있습니다.
-
state
노드가 존재하며, 노드는 desired
또는 reported
상태 정보를 포함하는 객체입니다.
-
desired
및 reported
노드는 객체이거나 null입니다. 이러한 개체 중 적어도 하나는 유효한 상태 정보를 포함해야 합니다.
-
desired
및 reported
개체의 깊이는 8개 노드를 초과할 수 없습니다.
-
clientToken
값의 길이는 64자를 초과할 수 없습니다.
-
version
값은 1
이상이어야 합니다.
ServiceError
-
내부 서비스 오류가 발생했거나 IPC 서비스에 대한 요청 수가 섀도우 관리자 구성 요소의 maxLocalRequestsPerSecondPerThing
및 maxTotalLocalRequestsRate
구성 매개 변수에 지정된 제한을 초과했습니다.
UnauthorizedError
-
구성 요소의 권한 부여 정책에는 이 작업에 필요한 권한이 포함되어 있지 않습니다.
예제
다음 예제는 사용자 지정 구성 요소 코드에서 이 작업을 호출하는 방법을 보여줍니다.
- Java (IPC client V1)
-
예: 사물 섀도우 업데이트
package com.aws.greengrass.docs.samples.ipc;
import com.aws.greengrass.docs.samples.ipc.util.IPCUtils;
import software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient;
import software.amazon.awssdk.aws.greengrass.UpdateThingShadowResponseHandler;
import software.amazon.awssdk.aws.greengrass.model.UnauthorizedError;
import software.amazon.awssdk.aws.greengrass.model.UpdateThingShadowRequest;
import software.amazon.awssdk.aws.greengrass.model.UpdateThingShadowResponse;
import software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class UpdateThingShadow {
public static final int TIMEOUT_SECONDS = 10;
public static void main(String[] args) {
// Use the current core device's name if thing name isn't set.
String thingName = args[0].isEmpty() ? System.getenv("AWS_IOT_THING_NAME") : args[0];
String shadowName = args[1];
byte[] shadowPayload = args[2].getBytes(StandardCharsets.UTF_8);
try (EventStreamRPCConnection eventStreamRPCConnection =
IPCUtils.getEventStreamRpcConnection()) {
GreengrassCoreIPCClient ipcClient =
new GreengrassCoreIPCClient(eventStreamRPCConnection);
UpdateThingShadowResponseHandler responseHandler =
UpdateThingShadow.updateThingShadow(ipcClient, thingName, shadowName,
shadowPayload);
CompletableFuture<UpdateThingShadowResponse> futureResponse =
responseHandler.getResponse();
try {
futureResponse.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
System.out.printf("Successfully updated shadow: %s/%s%n", thingName, shadowName);
} catch (TimeoutException e) {
System.err.printf("Timeout occurred while updating shadow: %s/%s%n", thingName,
shadowName);
} catch (ExecutionException e) {
if (e.getCause() instanceof UnauthorizedError) {
System.err.printf("Unauthorized error while updating shadow: %s/%s%n",
thingName, shadowName);
} else {
throw e;
}
}
} catch (InterruptedException e) {
System.out.println("IPC interrupted.");
} catch (ExecutionException e) {
System.err.println("Exception occurred when using IPC.");
e.printStackTrace();
System.exit(1);
}
}
public static UpdateThingShadowResponseHandler updateThingShadow(GreengrassCoreIPCClient greengrassCoreIPCClient, String thingName, String shadowName, byte[] shadowPayload) {
UpdateThingShadowRequest updateThingShadowRequest = new UpdateThingShadowRequest();
updateThingShadowRequest.setThingName(thingName);
updateThingShadowRequest.setShadowName(shadowName);
updateThingShadowRequest.setPayload(shadowPayload);
return greengrassCoreIPCClient.updateThingShadow(updateThingShadowRequest,
Optional.empty());
}
}
- Python (IPC client V1)
-
예: 사물 섀도우 업데이트
import awsiot.greengrasscoreipc
import awsiot.greengrasscoreipc.client as client
from awsiot.greengrasscoreipc.model import UpdateThingShadowRequest
TIMEOUT = 10
def sample_update_thing_shadow_request(thingName, shadowName, payload):
try:
# set up IPC client to connect to the IPC server
ipc_client = awsiot.greengrasscoreipc.connect()
# create the UpdateThingShadow request
update_thing_shadow_request = UpdateThingShadowRequest()
update_thing_shadow_request.thing_name = thingName
update_thing_shadow_request.shadow_name = shadowName
update_thing_shadow_request.payload = payload
# retrieve the UpdateThingShadow response after sending the request to the IPC server
op = ipc_client.new_update_thing_shadow()
op.activate(update_thing_shadow_request)
fut = op.get_response()
result = fut.result(TIMEOUT)
return result.payload
except InvalidArgumentsError as e:
# add error handling
...
# except ConflictError | UnauthorizedError | ServiceError
- JavaScript
-
예: 사물 섀도우 업데이트
import {
UpdateThingShadowRequest
} from 'aws-iot-device-sdk-v2/dist/greengrasscoreipc/model';
import * as greengrasscoreipc from 'aws-iot-device-sdk-v2/dist/greengrasscoreipc';
class UpdateThingShadow {
private ipcClient: greengrasscoreipc.Client;
private thingName: string;
private shadowName: string;
private shadowDocumentStr: string;
constructor() {
// Define args parameters here
this.thingName = "<define_your_own_thingName>";
this.shadowName = "<define_your_own_shadowName>";
this.shadowDocumentStr = "<define_your_own_payload>";
this.bootstrap();
}
async bootstrap() {
try {
this.ipcClient = await getIpcClient();
} catch (err) {
// parse the error depending on your use cases
throw err
}
try {
await this.handleUpdateThingShadowOperation(
this.thingName,
this.shadowName,
this.shadowDocumentStr);
} catch (err) {
// parse the error depending on your use cases
throw err
}
}
async handleUpdateThingShadowOperation(
thingName: string,
shadowName: string,
payloadStr: string
) {
const request: UpdateThingShadowRequest = {
thingName: thingName,
shadowName: shadowName,
payload: payloadStr
}
// make the UpdateThingShadow request
const response = await this.ipcClient.updateThingShadow(request);
}
}
export async function getIpcClient() {
try {
const ipcClient = greengrasscoreipc.createClient();
await ipcClient.connect()
.catch(error => {
// parse the error depending on your use cases
throw error;
});
return ipcClient
} catch (err) {
// parse the error depending on your use cases
throw err
}
}
const startScript = new UpdateThingShadow();
DeleteThingShadow
지정된 사물의 섀도우를 삭제합니다.
섀도우 관리자 v2.0.4부터 섀도우를 삭제하면 버전 번호가 증가합니다. 예를 들어 버전 MyThingShadow
1에서 섀도우를 삭제하면 삭제된 섀도우의 버전은 2입니다. 그런 다음 같은 이름으로 MyThingShadow
섀도우를 다시 만들면 해당 섀도우의 버전은 3입니다.
요청
이 작업의 요청에는 다음과 같은 매개 변수가 있습니다.
thingName
(Python:thing_name
)
-
사물의 이름입니다.
유형: string
shadowName
(Python:shadow_name
)
-
섀도우의 이름입니다. 사물의 클래식 섀도우를 지정하려면 이 매개변수를 빈 문자열 (""
) 으로 설정하십시오.
이 AWS IoT Greengrass 서비스는 AWSManagedGreengrassV2Deployment
명명된 섀도우를 사용하여 개별 코어 장치를 대상으로 하는 배포를 관리합니다. 이 이름이 지정된 섀도우는 서비스에서 사용하도록 예약되어 있습니다AWS IoT Greengrass. 이름이 지정된 이 섀도우를 업데이트하거나 삭제하지 마십시오.
유형: string
응답
이 작업의 응답에는 다음 정보가 포함됩니다.
Errors
이 작업을 수행하면 다음 오류가 반환될 수 있습니다.
InvalidArgumentsError
-
로컬 섀도우 서비스가 요청 파라미터를 검증할 수 없습니다. 요청에 잘못된 형식의 JSON이나 지원되지 않는 문자가 포함된 경우 이 문제가 발생할 수 있습니다.
ResourceNotFoundError
-
요청된 로컬 섀도우 문서를 찾을 수 없습니다.
ServiceError
-
내부 서비스 오류가 발생했거나 IPC 서비스에 대한 요청 수가 섀도우 관리자 구성 요소의 maxLocalRequestsPerSecondPerThing
및 maxTotalLocalRequestsRate
구성 매개변수에 지정된 제한을 초과했습니다.
UnauthorizedError
-
구성 요소의 권한 부여 정책에는 이 작업에 필요한 권한이 포함되어 있지 않습니다.
예제
다음 예제는 사용자 지정 구성 요소 코드에서 이 작업을 호출하는 방법을 보여줍니다.
- Java (IPC client V1)
-
예: 사물 섀도우 삭제
package com.aws.greengrass.docs.samples.ipc;
import com.aws.greengrass.docs.samples.ipc.util.IPCUtils;
import software.amazon.awssdk.aws.greengrass.DeleteThingShadowResponseHandler;
import software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient;
import software.amazon.awssdk.aws.greengrass.model.DeleteThingShadowRequest;
import software.amazon.awssdk.aws.greengrass.model.DeleteThingShadowResponse;
import software.amazon.awssdk.aws.greengrass.model.ResourceNotFoundError;
import software.amazon.awssdk.aws.greengrass.model.UnauthorizedError;
import software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class DeleteThingShadow {
public static final int TIMEOUT_SECONDS = 10;
public static void main(String[] args) {
// Use the current core device's name if thing name isn't set.
String thingName = args[0].isEmpty() ? System.getenv("AWS_IOT_THING_NAME") : args[0];
String shadowName = args[1];
try (EventStreamRPCConnection eventStreamRPCConnection =
IPCUtils.getEventStreamRpcConnection()) {
GreengrassCoreIPCClient ipcClient =
new GreengrassCoreIPCClient(eventStreamRPCConnection);
DeleteThingShadowResponseHandler responseHandler =
DeleteThingShadow.deleteThingShadow(ipcClient, thingName, shadowName);
CompletableFuture<DeleteThingShadowResponse> futureResponse =
responseHandler.getResponse();
try {
futureResponse.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
System.out.printf("Successfully deleted shadow: %s/%s%n", thingName, shadowName);
} catch (TimeoutException e) {
System.err.printf("Timeout occurred while deleting shadow: %s/%s%n", thingName,
shadowName);
} catch (ExecutionException e) {
if (e.getCause() instanceof UnauthorizedError) {
System.err.printf("Unauthorized error while deleting shadow: %s/%s%n",
thingName, shadowName);
} else if (e.getCause() instanceof ResourceNotFoundError) {
System.err.printf("Unable to find shadow to delete: %s/%s%n", thingName,
shadowName);
} else {
throw e;
}
}
} catch (InterruptedException e) {
System.out.println("IPC interrupted.");
} catch (ExecutionException e) {
System.err.println("Exception occurred when using IPC.");
e.printStackTrace();
System.exit(1);
}
}
public static DeleteThingShadowResponseHandler deleteThingShadow(GreengrassCoreIPCClient greengrassCoreIPCClient, String thingName, String shadowName) {
DeleteThingShadowRequest deleteThingShadowRequest = new DeleteThingShadowRequest();
deleteThingShadowRequest.setThingName(thingName);
deleteThingShadowRequest.setShadowName(shadowName);
return greengrassCoreIPCClient.deleteThingShadow(deleteThingShadowRequest,
Optional.empty());
}
}
- Python (IPC client V1)
-
예: 사물 섀도우 삭제
import awsiot.greengrasscoreipc
import awsiot.greengrasscoreipc.client as client
from awsiot.greengrasscoreipc.model import DeleteThingShadowRequest
TIMEOUT = 10
def sample_delete_thing_shadow_request(thingName, shadowName):
try:
# set up IPC client to connect to the IPC server
ipc_client = awsiot.greengrasscoreipc.connect()
# create the DeleteThingShadow request
delete_thing_shadow_request = DeleteThingShadowRequest()
delete_thing_shadow_request.thing_name = thingName
delete_thing_shadow_request.shadow_name = shadowName
# retrieve the DeleteThingShadow response after sending the request to the IPC server
op = ipc_client.new_delete_thing_shadow()
op.activate(delete_thing_shadow_request)
fut = op.get_response()
result = fut.result(TIMEOUT)
return result.payload
except InvalidArgumentsError as e:
# add error handling
...
# except ResourceNotFoundError | UnauthorizedError | ServiceError
- JavaScript
-
예: 사물 섀도우 삭제
import {
DeleteThingShadowRequest
} from 'aws-iot-device-sdk-v2/dist/greengrasscoreipc/model';
import * as greengrasscoreipc from 'aws-iot-device-sdk-v2/dist/greengrasscoreipc';
class DeleteThingShadow {
private ipcClient: greengrasscoreipc.Client;
private thingName: string;
private shadowName: string;
constructor() {
// Define args parameters here
this.thingName = "<define_your_own_thingName>";
this.shadowName = "<define_your_own_shadowName>";
this.bootstrap();
}
async bootstrap() {
try {
this.ipcClient = await getIpcClient();
} catch (err) {
// parse the error depending on your use cases
throw err
}
try {
await this.handleDeleteThingShadowOperation(this.thingName, this.shadowName)
} catch (err) {
// parse the error depending on your use cases
throw err
}
}
async handleDeleteThingShadowOperation(thingName: string, shadowName: string) {
const request: DeleteThingShadowRequest = {
thingName: thingName,
shadowName: shadowName
}
// make the DeleteThingShadow request
const response = await this.ipcClient.deleteThingShadow(request);
}
}
export async function getIpcClient() {
try {
const ipcClient = greengrasscoreipc.createClient();
await ipcClient.connect()
.catch(error => {
// parse the error depending on your use cases
throw error;
});
return ipcClient
} catch (err) {
// parse the error depending on your use cases
throw err
}
}
const startScript = new DeleteThingShadow();
ListNamedShadowsForThing
지정된 사물의 이름이 지정된 섀도우를 나열하십시오.
요청
이 작업의 요청에는 다음과 같은 매개변수가 있습니다.
thingName
(Python:thing_name
)
-
사물의 이름입니다.
유형: string
pageSize
(Python:page_size
)
-
(선택 사항) 각 호출에서 반환되는 섀도우 이름 수.
유형: integer
기본값: 25
최대: 100
nextToken
(Python:next_token
)
-
(선택 사항) 다음 결과 세트를 검색하기 위한 토큰입니다. 이 값은 페이징된 결과에서 반환되며 다음 페이지를 반환하는 호출에 사용됩니다.
유형: string
응답
이 작업의 응답에는 다음 정보가 포함됩니다.
results
-
섀도우 이름 목록.
유형: array
timestamp
-
(선택 사항) 응답이 생성된 날짜 및 시간.
유형: integer
nextToken
(Python:next_token
)
-
(선택 사항) 시퀀스의 다음 페이지를 검색하기 위한 페이징 요청에서 사용할 토큰 값입니다. 반환할 섀도우 이름이 더 이상 없을 때는 이 토큰이 표시되지 않습니다.
유형: string
요청된 페이지 크기가 응답의 섀도우 이름 수와 정확히 일치하면 이 토큰이 존재하지만 사용하면 빈 목록이 반환됩니다.
Errors
이 작업을 수행하면 다음 오류가 반환될 수 있습니다.
InvalidArgumentsError
-
로컬 섀도우 서비스가 요청 파라미터를 검증할 수 없습니다. 요청에 잘못된 형식의 JSON이나 지원되지 않는 문자가 포함된 경우 이 문제가 발생할 수 있습니다.
ResourceNotFoundError
-
요청된 로컬 섀도우 문서를 찾을 수 없습니다.
ServiceError
-
내부 서비스 오류가 발생했거나 IPC 서비스에 대한 요청 수가 섀도우 관리자 구성 요소의 maxLocalRequestsPerSecondPerThing
및 maxTotalLocalRequestsRate
구성 매개변수에 지정된 제한을 초과했습니다.
UnauthorizedError
-
구성 요소의 권한 부여 정책에는 이 작업에 필요한 권한이 포함되어 있지 않습니다.
예제
다음 예제는 사용자 지정 구성 요소 코드에서 이 작업을 호출하는 방법을 보여줍니다.
- Java (IPC client V1)
-
예: 이름이 지정된 사물의 그림자 나열
package com.aws.greengrass.docs.samples.ipc;
import com.aws.greengrass.docs.samples.ipc.util.IPCUtils;
import software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient;
import software.amazon.awssdk.aws.greengrass.ListNamedShadowsForThingResponseHandler;
import software.amazon.awssdk.aws.greengrass.model.ListNamedShadowsForThingRequest;
import software.amazon.awssdk.aws.greengrass.model.ListNamedShadowsForThingResponse;
import software.amazon.awssdk.aws.greengrass.model.ResourceNotFoundError;
import software.amazon.awssdk.aws.greengrass.model.UnauthorizedError;
import software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class ListNamedShadowsForThing {
public static final int TIMEOUT_SECONDS = 10;
public static void main(String[] args) {
// Use the current core device's name if thing name isn't set.
String thingName = args[0].isEmpty() ? System.getenv("AWS_IOT_THING_NAME") : args[0];
try (EventStreamRPCConnection eventStreamRPCConnection =
IPCUtils.getEventStreamRpcConnection()) {
GreengrassCoreIPCClient ipcClient =
new GreengrassCoreIPCClient(eventStreamRPCConnection);
List<String> namedShadows = new ArrayList<>();
String nextToken = null;
try {
// Send additional requests until there's no pagination token in the response.
do {
ListNamedShadowsForThingResponseHandler responseHandler =
ListNamedShadowsForThing.listNamedShadowsForThing(ipcClient, thingName,
nextToken, 25);
CompletableFuture<ListNamedShadowsForThingResponse> futureResponse =
responseHandler.getResponse();
ListNamedShadowsForThingResponse response =
futureResponse.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
List<String> responseNamedShadows = response.getResults();
namedShadows.addAll(responseNamedShadows);
nextToken = response.getNextToken();
} while (nextToken != null);
System.out.printf("Successfully got named shadows for thing %s: %s%n", thingName,
String.join(",", namedShadows));
} catch (TimeoutException e) {
System.err.println("Timeout occurred while listing named shadows for thing: " + thingName);
} catch (ExecutionException e) {
if (e.getCause() instanceof UnauthorizedError) {
System.err.println("Unauthorized error while listing named shadows for " +
"thing: " + thingName);
} else if (e.getCause() instanceof ResourceNotFoundError) {
System.err.println("Unable to find thing to list named shadows: " + thingName);
} else {
throw e;
}
}
} catch (InterruptedException e) {
System.out.println("IPC interrupted.");
} catch (ExecutionException e) {
System.err.println("Exception occurred when using IPC.");
e.printStackTrace();
System.exit(1);
}
}
public static ListNamedShadowsForThingResponseHandler listNamedShadowsForThing(GreengrassCoreIPCClient greengrassCoreIPCClient, String thingName, String nextToken, int pageSize) {
ListNamedShadowsForThingRequest listNamedShadowsForThingRequest =
new ListNamedShadowsForThingRequest();
listNamedShadowsForThingRequest.setThingName(thingName);
listNamedShadowsForThingRequest.setNextToken(nextToken);
listNamedShadowsForThingRequest.setPageSize(pageSize);
return greengrassCoreIPCClient.listNamedShadowsForThing(listNamedShadowsForThingRequest,
Optional.empty());
}
}
- Python (IPC client V1)
-
예: 이름이 지정된 사물의 그림자 나열
import awsiot.greengrasscoreipc
import awsiot.greengrasscoreipc.client as client
from awsiot.greengrasscoreipc.model import ListNamedShadowsForThingRequest
TIMEOUT = 10
def sample_list_named_shadows_for_thing_request(thingName, nextToken, pageSize):
try:
# set up IPC client to connect to the IPC server
ipc_client = awsiot.greengrasscoreipc.connect()
# create the ListNamedShadowsForThingRequest request
list_named_shadows_for_thing_request = ListNamedShadowsForThingRequest()
list_named_shadows_for_thing_request.thing_name = thingName
list_named_shadows_for_thing_request.next_token = nextToken
list_named_shadows_for_thing_request.page_size = pageSize
# retrieve the ListNamedShadowsForThingRequest response after sending the request to the IPC server
op = ipc_client.new_list_named_shadows_for_thing()
op.activate(list_named_shadows_for_thing_request)
fut = op.get_response()
list_result = fut.result(TIMEOUT)
# additional returned fields
timestamp = list_result.timestamp
next_token = result.next_token
named_shadow_list = list_result.results
return named_shadow_list, next_token, timestamp
except InvalidArgumentsError as e:
# add error handling
...
# except ResourceNotFoundError | UnauthorizedError | ServiceError
- JavaScript
-
예: 사물의 이름이 지정된 그림자 나열하기
import {
ListNamedShadowsForThingRequest
} from 'aws-iot-device-sdk-v2/dist/greengrasscoreipc/model';
import * as greengrasscoreipc from 'aws-iot-device-sdk-v2/dist/greengrasscoreipc';
class listNamedShadowsForThing {
private ipcClient: greengrasscoreipc.Client;
private thingName: string;
private pageSizeStr: string;
private nextToken: string;
constructor() {
// Define args parameters here
this.thingName = "<define_your_own_thingName>";
this.pageSizeStr = "<define_your_own_pageSize>";
this.nextToken = "<define_your_own_token>";
this.bootstrap();
}
async bootstrap() {
try {
this.ipcClient = await getIpcClient();
} catch (err) {
// parse the error depending on your use cases
throw err
}
try {
await this.handleListNamedShadowsForThingOperation(this.thingName,
this.nextToken, this.pageSizeStr);
} catch (err) {
// parse the error depending on your use cases
throw err
}
}
async handleListNamedShadowsForThingOperation(
thingName: string,
nextToken: string,
pageSizeStr: string
) {
let request: ListNamedShadowsForThingRequest = {
thingName: thingName,
nextToken: nextToken,
};
if (pageSizeStr) {
request.pageSize = parseInt(pageSizeStr);
}
// make the ListNamedShadowsForThing request
const response = await this.ipcClient.listNamedShadowsForThing(request);
const shadowNames = response.results;
}
}
export async function getIpcClient(){
try {
const ipcClient = greengrasscoreipc.createClient();
await ipcClient.connect()
.catch(error => {
// parse the error depending on your use cases
throw error;
});
return ipcClient
} catch (err) {
// parse the error depending on your use cases
throw err
}
}
const startScript = new listNamedShadowsForThing();