AWS IoT Greengrass
Developer Guide

Create and Package the Lambda Function

  1. Download the Lambda function code to your computer (not the Greengrass core device):

    1. In a web browser, open the file on GitHub.

    2. Choose Raw to open the unformatted version of the file.

                                    GitHub controls with the Raw button highlighted.
    3. Use Ctrl + S (or Command + S for the Mac) to save a copy of the file. Save the file to a folder that contains the greengrasssdk folder.


    For UNIX-like systems, you can run the following Terminal command to download the file:

  2. Package the file with the SDK into a .zip file, as described in Module 3 (Part 1). Name the package

                            Screenshot showing zipped contents of
  3. In the Lambda console, create a Python 2.7 function named Greengrass_HelloWorld_Counter, as described in Module 3 (Part 1). You can use the existing role.

  4. Upload your Lambda function deployment package:

    1. On the Configuration tab, under Function code, set the following fields:

      • For Code entry type, choose Upload a .zip file.

      • For Runtime, choose Python 2.7.

      • For Handler, enter greengrassHelloWorldCounter.function_handler

    2. Choose Upload, and then choose

                            Function code screenshot with Code entry type set to Upload a
                                .zip file, Runtime set to Python 2.7, Handler set to
                                greengrassHelloWorldCounter.function_handler, and Function package
                                set to
    3. At the top of the page, choose Save.


      The Test button on the AWS Lambda console doesn't work with this function. The AWS IoT Greengrass Core SDK doesn't contain modules that are required to run your Greengrass Lambda functions independently in the AWS Lambda console. These modules (for example, greengrass_common) are supplied to the functions after they are deployed to your Greengrass core.

  5. Publish the first version of the function:

    1. From Actions, choose Publish new version. For Version description, enter First version.

    2. Choose Publish.

  6. Create an alias for the function version:

    1. From the Actions menu, choose Create alias, and set the following values:

      • For Name, enter GG_HW_Counter.

      • For Version, choose 1.

    2. Choose Create.

                            Create a new alias screenshot with the Name field set to
                                GG_HW_Counter, the Version field set to 1, and the Create button

    Aliases create a single entity for your Lambda function that AWS IoT Greengrass devices can subscribe to without having to update subscriptions with Lambda version numbers every time the function is modified.