Import a Lambda function as a component (console)
When you use the AWS IoT Greengrass console
Before you begin, review the requirements to run Lambda functions on Greengrass devices.
Tasks
- Step 1: Choose a Lambda function to import
- Step 2: Configure Lambda function parameters
- Step 3: (Optional) Specify supported platforms for the Lambda function
- Step 4: (Optional) Specify component dependencies for the Lambda function
- Step 5: (Optional) Run the Lambda function in a container
- Step 6: Create the Lambda function component
Step 1: Choose a Lambda function to import
-
In the AWS IoT Greengrass console
navigation menu, choose Components. -
On the Components page, choose Create component.
-
On the Create component page, under Component information, choose Import Lambda function.
-
In Lambda function, search for and choose the Lambda function that you want to import.
AWS IoT Greengrass creates the component with the name of the Lambda function.
-
In Lambda function version, choose the version to import. You can't choose Lambda aliases like
$LATEST
.AWS IoT Greengrass creates the component with the version of the Lambda function as a valid semantic version. For example, if your function version is
3
, the component version becomes3.0.0
.
Step 2: Configure Lambda function parameters
On the Create component page, under Lambda function configuration, configure the following parameters to use to run the Lambda function.
-
(Optional) Add the list of event sources to which the Lambda function subscribes for work messages. You can specify event sources to subscribe this function to local publish/subscribe messages and AWS IoT Core MQTT messages. The Lambda function is called when it receives a message from an event source.
Note
To subscribe this function to messages from other Lambda functions or components, deploy the legacy subscription router component when you deploy this Lambda function component. When you deploy the legacy subscription router component, specify the subscriptions that the Lambda function uses.
Under Event sources, do the following to add an event source:
-
For each event source that you add, specify the following options:
-
Topic – The topic to subscribe for messages.
-
Type – The type of event source. Choose from the following options:
-
Local publish/subscribe – Subscribe to local publish/subscribe messages.
If you use Greengrass nucleus v2.6.0 or later and Lambda manager v2.2.5 or later, you can use MQTT topic wildcards (
+
and#
) in the Topic when you specify this type. -
AWS IoT Core MQTT – Subscribe to AWS IoT Core MQTT messages.
You can use MQTT topic wildcards (
+
and#
) in the Topic when you specify this type.
-
-
-
To add another event source, choose Add event source and repeat the previous step. To remove an event source, choose Remove next to the event source that you want to remove.
-
-
For Timeout (seconds), enter the maximum amount of time in seconds that a non-pinned Lambda function can run before it times out. The default is 3 seconds.
-
For Pinned, choose whether the Lambda function component is pinned. The default is True.
-
A pinned (or long-lived) Lambda function starts when AWS IoT Greengrass starts and keeps running in its own container.
-
A non-pinned (or on-demand) Lambda function starts only when it receives a work item and exits after it remains idle for a specified maximum idle time. If the function has multiple work items, the AWS IoT Greengrass Core software creates multiple instances of the function.
-
-
(Optional) Under Additional parameters, set the following Lambda function parameters.
-
Status timeout (seconds) – The interval in seconds at which the Lambda function component sends status updates to the Lambda manager component. This parameter applies only to pinned functions. The default is 60 seconds.
-
Maximum queue size – The maximum size of the message queue for the Lambda function component. The AWS IoT Greengrass Core software stores messages in a FIFO (first-in, first-out) queue until it can run the Lambda function to consume each message. The default is 1,000 messages.
-
Maximum number of instances – The maximum number of instances that a non-pinned Lambda function can run at the same time. The default is 100 instances.
-
Maximum idle time (seconds) – The maximum amount of time in seconds that a non-pinned Lambda function can idle before the AWS IoT Greengrass Core software stops its process. The default is 60 seconds.
-
Encoding type – The type of payload that the Lambda function supports. Choose from the following options:
-
JSON
-
Binary
The default is JSON.
-
-
-
(Optional) Specify the list of command line arguments to pass to the Lambda function when it runs.
-
Under Additional parameters, Process arguments, choose Add argument.
-
For each argument that you add, enter the argument that you want to pass to the function.
-
To remove an argument, choose Remove next to the argument that you want to remove.
-
-
(Optional) Specify the environment variables that are available to the Lambda function when it runs. Environment variables enable you to store and update configuration settings without the need to change function code.
-
Under Additional parameters, Environment variables, choose Add environment variable.
-
For each environment variable that you add, specify the following options:
-
Key – The variable name.
-
Value – The default value for this variable.
-
-
To remove an environment variable, choose Remove next to the environment variable that you want to remove.
-
Step 3: (Optional) Specify supported platforms for the Lambda function
All core devices have attributes for operating system and architecture. When you deploy the Lambda function component, the AWS IoT Greengrass Core software compares the platform values that you specify with the platform attributes on the core device to determine whether the Lambda function is supported on that device.
Note
You can also specify custom platform attributes when you deploy the Greengrass nucleus component to a core device. For more information, see the platform overrides parameter of the Greengrass nucleus component.
Under Lambda function configuration, Additional parameters, Platforms, do the following to specify the platforms that this Lambda function supports.
-
For each platform, specify the following options:
-
Operating system – The name of the operating system for the platform. Currently, the only supported value is
linux
. -
Architecture – The processor architecture for the platform. Supported values are:
-
amd64
-
arm
-
aarch64
-
x86
-
-
-
To add another platform, choose Add platform and repeat the previous step. To remove a supported platform, choose Remove next to the platform that you want to remove.
Step 4: (Optional) Specify component dependencies for the Lambda function
Component dependencies identify additional AWS-provided components or custom components that your function uses. When you deploy the Lambda function component, the deployment includes these dependencies for your function to run.
Important
To import a Lambda function that you created to run on AWS IoT Greengrass V1, you must define individual component dependencies for the features that your function uses, such as secrets, local shadows, and stream manager. Define these components as hard dependencies so that your Lambda function component restarts if the dependency changes state. For more information, see Import V1 Lambda functions.
Under Lambda function configuration, Additional parameters, Component dependencies, complete the following steps to specify the component dependencies for your Lambda function.
-
Choose Add dependency.
-
For each component dependency that you add, specify the following options:
-
Component name – The component name. For example, enter
aws.greengrass.StreamManager
to include the stream manager component. -
Version requirement – The npm-style semantic version constraint that identifies the compatible versions of this component dependency. You can specify a single version or a range of versions. For example, enter
^1.0.0
to specify that this Lambda function depends on any version in the first major version of the stream manager component. For more information about semantic version constraints, see the npm semver calculator. -
Type – The type of dependency. Choose from the following options:
-
Hard – The Lambda function component restarts if the dependency changes state. This is the default selection.
-
Soft – The Lambda function component doesn't restart if the dependency changes state.
-
-
-
To remove a component dependency, choose Remove next to the component dependency
Step 5: (Optional) Run the Lambda function in a container
By default, Lambda functions run in an isolated runtime environment inside the AWS IoT Greengrass Core software. You can also choose to run the Lambda function as a process without any isolation (that is, in No container mode).
Under Linux process configuration, for Isolation mode, choose from the following options to select the containerization for your Lambda function:
-
Greengrass container – The Lambda function runs in a container. This is the default selection.
-
No container – The Lambda function runs as a process without any isolation.
If you run the Lambda function in a container, complete the following steps to configure the process configuration for the Lambda function.
-
Configure the amount of memory and the system resources, such as volumes and devices, to make available to the container.
Under Container parameters, do the following.
-
For Memory size, enter the memory size that you want to allocate to the container. You can specify the memory size in MB or kB.
-
For Read-only sys folder, choose whether or not the container can read information from the device's
/sys
folder. The default is False.
-
-
(Optional) Configure the local volumes that the containerized Lambda function can access. When you define a volume, the AWS IoT Greengrass Core software mounts the source files to the destination inside the container.
-
Under Volumes, choose Add volume.
-
For each volume that you add, specify the following options:
-
Physical volume – The path to the source folder on the core device.
-
Logical volume – The path to the destination folder in the container.
-
Permission – (Optional) The permission to access the source folder from the container. Choose from the following options:
-
Read-only – The Lambda function has read-only access to the source folder. This is the default selection.
-
Read-write – The Lambda function has read/write access to the source folder.
-
-
Add group owner – (Optional) Whether or not to add the system group that runs the Lambda function component as an owner of the source folder. The default is False.
-
-
To remove a volume, choose Remove next to the volume that you want to remove.
-
-
(Optional) Configure the local system devices that the containerized Lambda function can access.
-
Under Devices, choose Add device.
-
For each device that you add, specify the following options:
-
Mount path – The path to the system device on the core device.
-
Permission – (Optional) The permission to access the system device from the container. Choose from the following options:
-
Read-only – The Lambda function has read-only access to the system device. This is the default selection.
-
Read-write – The Lambda function has read/write access to the source folder.
-
-
Add group owner – (Optional) Whether or not to add the system group that runs the Lambda function component as an owner of the system device. The default is False.
-
-
Step 6: Create the Lambda function component
After you configure settings for your Lambda function component, choose Create to finish creating the new component.
To run the Lambda function on your core device, you can then deploy the new component to your core devices. For more information, see Deploy AWS IoT Greengrass components to devices.