End of support notice: On October 7th, 2026, Amazon will discontinue support for Amazon IoT Greengrass Version 1. After October 7th, 2026, you will no longer be able to access the Amazon IoT Greengrass V1 resources. For more information, please visit Migrate from Amazon IoT Greengrass Version 1.
Create and package the Lambda function
In this step, you:
-
Create a Lambda function deployment package that contains the function code and dependencies.
-
Use the Lambda console to create a Lambda function and upload the deployment package.
-
Publish a version of the Lambda function and create an alias that points to the version.
-
On your computer, go to the Amazon IoT Greengrass Core SDK for Python that you downloaded and extracted in Create and package a Lambda function in Module 3-1.
The Lambda function in this module uses:
-
The
greengrassHelloWorldCounter.pyfile inexamples\HelloWorldCounter. This is your Lambda function code. -
The
greengrasssdkfolder. This is the SDK.
-
-
Create a Lambda function deployment package:
-
Copy the
greengrasssdkfolder into theHelloWorldCounterfolder that containsgreengrassHelloWorldCounter.py. -
Save
greengrassHelloWorldCounter.pyand thegreengrasssdkfolder to azipfile namedhello_world_counter_python_lambda.zip. Thepyfile andgreengrasssdkfolder must be in the root of the directory.
On UNIX-like systems (including the Mac terminal) that have
zipinstalled, you can use the following command to package the file and folder:zip -r hello_world_counter_python_lambda.zip greengrasssdk greengrassHelloWorldCounter.py
Now you're ready to create your Lambda function and upload the deployment package.
-
-
Open the Lambda console and choose Create function.
-
Choose Author from scratch.
-
Name your function
Greengrass_HelloWorld_Counter, and set the remaining fields as follows:-
For Runtime, choose Python 3.7.
-
For Permissions, keep the default setting. This creates an execution role that grants basic Lambda permissions. This role isn't used by Amazon IoT Greengrass. Or, you can reuse the role that you created in Module 3-1.
Choose Create function.
-
-
Upload your Lambda function deployment package.
-
On the Code tab, under Code source, choose Upload from. From the dropdown, choose .zip file.
-
Choose Upload, and then choose your
hello_world_counter_python_lambda.zipdeployment package. Then, choose Save. -
On the Code tab for the function, under Runtime settings, choose Edit, and then enter the following values.
-
For Runtime, choose Python 3.7.
-
For Handler, enter
greengrassHelloWorldCounter.function_handler
-
-
Choose Save.
Note
The Test button on the Amazon Lambda console doesn't work with this function. The Amazon IoT Greengrass Core SDK doesn't contain modules that are required to run your Greengrass Lambda functions independently in the Amazon Lambda console. These modules (for example,
greengrass_common) are supplied to the functions after they are deployed to your Greengrass core.
-
-
Publish the first version of the function.
-
From the Actions menu at the top of the page, choose Publish new version. For Version description, enter
First version. -
Choose Publish.
-
-
Create an alias for the function version.
-
From the Actions menu at the top of the page, choose Create alias.
-
For Name, enter
GG_HW_Counter. -
For Version, choose 1.
-
Choose Save.
Aliases create a single entity for your Lambda function that Greengrass devices can subscribe to. This way, you don't have to update subscriptions with new Lambda function version numbers every time the function is modified.
-