Menu
AWS Greengrass
Developer Guide

Create and Package the Lambda Function

  1. On you computer (not the AWS Greengrass device), open a web browser, navigate to the GitHub greengrassHelloWorldCounter.py repository, choose Raw, press Ctrl + S (or Command + S for the Mac) and save the Lambda greengrassHelloWorldCounter.py file to the folder containing the three SDK folders greengrasssdk, greengrass_common, and greengrass_ipc_python_sdk.

    Note

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

    sudo wget https://raw.githubusercontent.com/aws-samples/aws-greengrass-samples/master/hello-world-counter-python/greengrassHelloWorldCounter.py

    Next, package the Lambda file with the three SDK folders into a .zip file, as described in Module 3 (Part 1). Name the package hello_world_counter_python_lambda.zip, as indicated below.

    
                            Screenshot showing zipped contents of
                                hello_word_counter_python_lambda.zip.
  2. Upload your Lambda function package into the AWS Lambda console. Name your function Greengrass_HelloWorld_Counter with the default role you created in Module 3 (Part 1). For Handler, type greengrassHelloWorldCounter.function_handler.

    
                            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 hello_world_counter_python_lambda.zip.

    Choose Save.

    Under Actions, choose Publish new version and describe it as First version, then choose Publish.

    Under Actions, choose Create alias for version 1 and name it GG_HW_Counter, then 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
                                highlighted.

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