Amazon IoT Greengrass Version 1 entered the extended life phase on June 30, 2023. For more information, see the Amazon IoT Greengrass V1 maintenance policy. After this date, Amazon IoT Greengrass V1 won't release updates that provide features, enhancements, bug fixes, or security patches. Devices that run on Amazon IoT Greengrass V1 won't be disrupted and will continue to operate and to connect to the cloud. We strongly recommend that you migrate to Amazon IoT Greengrass Version 2, which adds significant new features and support for additional platforms.
Test on-demand Lambda functions
An on-demand Lambda function is similar in functionality to a cloud-based Amazon Lambda function. Multiple invocations of an on-demand Lambda function can run in parallel. An invocation of the Lambda function creates a separate container to process invocations or reuses an existing container, if resources permit. Any variables or preprocessing that are defined outside of the function handler are not retained when containers are created.
-
On the group configuration page, choose the Lambda functions tab.
-
Under My Lambda functions, choose the Greengrass_HelloWorld_Counter Lambda function.
-
On the Greengrass_HelloWorld_Counter details page, choose Edit.
-
For Pinned, choose False, and then choose Save.
-
On the group configuration page, choose Deploy.
-
After your deployment is complete, return to the Amazon IoT console home page and choose Test.
-
Configure the following fields:
-
For Subscription topic, enter
hello/world/counter
. -
For Quality of Service, choose 0.
-
For MQTT payload display, choose Display payloads as strings.
-
-
Choose Subscribe.
Note
You should not see any messages after you subscribe.
-
To test the on-demand lifecycle, invoke the function by publishing a message to the
hello/world/counter/trigger
topic. You can use the default message.-
Choose Publish three times quickly, within five seconds of each press of the button.
Each publish invokes the function handler and creates a container for each invocation. The invocation count is not incremented for the three times you triggered the function because each on-demand Lambda function has its own container/sandbox.
-
After approximately 30 seconds, choose Publish to topic. The invocation count should be incremented to 2. This shows that a container created from an earlier invocation is being reused, and that preprocessing variables outside of the function handler were stored.
-
You should now understand the two types of Lambda functions that can run on the Amazon IoT Greengrass core. The next module, Module 4, shows you how local IoT devices can interact in an Amazon IoT Greengrass group.