Using Amazon Lambda with an Amazon Snowball Edge - Amazon Snowball Edge Developer Guide
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Using Amazon Lambda with an Amazon Snowball Edge

Amazon Lambda powered by Amazon IoT Greengrass is a compute service that lets you to run serverless code (Lambda functions) locally on Snowball Edge devices. You can use Lambda to invoke Lambda functions on a Snowball Edge device with Message Queuing Telemetry Transport (MQTT) messages, run Python code in Lambda functions, and use them to call public Amazon service endpoints in the cloud. To use Lambda functions with Snowball Edge devices, you must create your Snowball Edge jobs in an Amazon Web Services Region supported by Amazon IoT Greengrass. For a list of valid Amazon Web Services Regions, see Amazon IoT Greengrass in the Amazon Web Services General Reference. Lambda on Snowball Edge is available in Regions where Lambda and Snowball Edge devices are available.

Note

If you allocate the minimum recommendation of 128 MB of memory for each of your functions, you can have up to seven Lambda functions in a single job.

Before You Start

Before you create a Lambda function in the Python language to run on your Snowball Edge, we recommend that you familiarize yourself with the following services, concepts, and related topics.

Prerequisites for Amazon IoT Greengrass

Amazon IoT Greengrass is software that extends Amazon Web Services Cloud capabilities to local devices. Amazon IoT Greengrass makes it possible for local devices to collect and analyze data closer to the source of information, while also securely communicating with each other on local networks. More specifically, developers who use Amazon IoT Greengrass can author serverless code (Lambda functions) in the Amazon Web Services Cloud. They can then conveniently deploy this code to devices for local execution of applications.

The following Amazon IoT Greengrass concepts are important to understand when using Amazon IoT Greengrass with a Snowball Edge:

  • Amazon IoT Greengrass requirements – For a full list of Amazon IoT Greengrass requirements, see Requirements in the Amazon IoT Greengrass Version 2 Developer Guide.

  • Amazon IoT Greengrass core – Download the Amazon IoT Greengrass core software and install it on an EC2 instance running on the device. See Using Amazon IoT Greengrass on Amazon EC2 instances in this guide.

    To use Lambda functions on a Snowball Edge device, you must first install Amazon IoT Greengrass Core software on an Amazon EC2 instance on the device. The Lambda functions you plan to use on the Snowball Edge device must be created by the same account you will use to install Amazon IoT Greengrass on the Snowball Edge device. For information about installing Amazon IoT Greengrass on your Snowball Edge device, see Using Amazon IoT Greengrass to run pre-installed software on Amazon EC2-compatible instances.

  • Amazon IoT Greengrass group – A Snowball Edge device is part of an Amazon IoT Greengrass group as the group's core device. For more information about groups, see Amazon Greengrass IoT Groups in the Amazon IoT Greengrass Developer Guide.

  • MQTT – Amazon IoT Greengrass uses the industry-standard, lightweight MQTT protocol to communicate within a group. Any device or software compatible with MQTT in your Amazon IoT Greengrass group can invoke MQTT messages. These messages can invoke Lambda functions, if you define the related MQTT message to do so.

Prerequisites for Amazon Lambda

Amazon Lambda is a compute service that lets you run code without provisioning or managing servers. The following Lambda concepts are important to understand when using Lambda with a Snowball Edge:

  • Lambda functions – Your custom code, uploaded and published to Lambda and used on a Snowball Edge. For more information, see Lambda Functions in the Amazon Lambda Developer Guide.

  • Lambda console – The console in which you upload, update, and publish your Python-language Lambda functions for use on a Snowball Edge. For more information about the Lambda console, see Lambda console in the Amazon Lambda Developer Guide.

  • Python – The high-level programming language used for your Lambda functions powered by Amazon IoT Greengrass on a Snowball Edge. Amazon IoT Greengrass supports Python version 3.8.x.

Deploy a Lambda function to a Snowball Edge device

To run a Lambda function on a Snowball Edge device in an Amazon IoT Greengrass group, import the function as a component. For complete information about importing a function as a component using the Amazon IoT Greengrass console, see Import a Lambda function as a component (console) in the Amazon IoT Greengrass Version 2 Developer Guide.

  1. In the Amazon IoT console, on the Greengrass components page, choose Create component.

  2. In Component source, choose Import Lambda function. In Lambda function, choose the name of your function. In Lambda function version, choose the version of your function.

  3. To subscribe the function to messages on which it can act, choose Add event source and choose the event. In Timeout (seconds), provide a timeout period in seconds.

  4. In Pinned, choose whether or not to pin your function.

  5. Choose Create component

  6. Choose Deploy.

  7. In Deployment, choose Add to existing deployment, then choose your Greengrass group. Choose Next.

  8. In Public components, choose these components:

    • aws.greengrass.Cli

    • aws.greengrass.LambdaLauncher

    • aws.greengrass.LambdaManager

    • aws.greengrass.LambdaRuntimes

    • aws.greengrass.Nucleus

  9. Choose Deploy.