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 年前292 查看次数
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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则