greengrass lambda to be triggered by shadow update

0

I've created a Lambda that does something when a named shadow updates

#greengrass-cli component list

....
Component Name: mtdshadowconfiglambda-dev-sync_remote_config#2
Version: 1.0.18
State: RUNNING
Configuration: {"containerMode":"NoContainer","containerParams":{"devices":{},"memorySize":16000.0,"mountROSysfs":false,"volumes":{}},"inputPayloadEncodingType":"json","lambdaExecutionParameters":{"EnvironmentVariables":{}},"maxIdleTimeInSeconds":60.0,"maxInstancesCount":100.0,"maxQueueSize":1000.0,"pinned":false,"pubsubTopics":{"0":{"topic":"$aws/things/+/shadow/name/#","type":"IOT_CORE"}},"statusTimeoutInSeconds":60.0,"timeoutInSeconds":30.0}
......

i'm trying to lock down the trigger a bit more to:
{"topic":"$aws/things/${AWS_IOT_THING_NAME}/shadow/name/config#","type":"IOT_CORE"}
(side question, is this how you do this with the environment variable AWS_IOT_THING_NAME ? )

so that's what i enter in the console when i create a new version of the lambda, however after everything is pushed to the device the same topic is retained even though the version number has updated:

Component Name: mtdshadowconfiglambda-dev-sync_remote_config
Version: 1.0.23
State: FINISHED
Configuration: {"containerMode":"NoContainer","containerParams":{"devices":{},"memorySize":16000.0,"mountROSysfs":false,"volumes":{}},"inputPayloadEncodingType":"json","lambdaExecutionParameters":{"EnvironmentVariables":{}},"maxIdleTimeInSeconds":60.0,"maxInstancesCount":100.0,"maxQueueSize":1000.0,"pinned":false,"pubsubTopics":{"0":{"topic":"$aws/things/+/shadow/name/#","type":"IOT_CORE"}},"statusTimeoutInSeconds":60.0,"timeoutInSeconds":30.0}

is there a way to change a lambda's trigger once it is installed ?

Edited by: clogwog on Oct 6, 2021 3:30 AM

Edited by: clogwog on Oct 6, 2021 3:42 AM

clogwog
已提問 3 年前檢視次數 293 次
2 個答案
0
已接受的答案

Hello,
Thank you for your interested in Greengrass V2. The issue you are having is because you must use a RESET configuration inside the deployment in order to have the lambda use the updated default configuration. See https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#reset-configuration-update and https://forums.aws.amazon.com/thread.jspa?messageID=972603#972603 for more information.

Answering your side question, subscribing to topics is entirely configuration driven for Lambdas, so you cannot use environment variables. If you wish to have programatic subscriptions then you must use a native Greengrass V2 component (non-lambda) and use our IPC SDK https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-iot-core-mqtt.html#ipc-operation-subscribetoiotcore.

Cheers,
Michael

AWS
專家
已回答 3 年前
0

Thank you @MichaelDombrowski-AWS !!, that all worked out.

It's a shame the environment variables aren't available at that time for the trigger. The server side lambda's have it available and they are very handy.

Kind regards,
Tom

clogwog
已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南