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
asked 3 years ago286 views
2 Answers
0
Accepted Answer

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
EXPERT
answered 3 years ago
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
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions