Quickstart

The AWS Greengrass Core SDK is meant to be used by AWS Lambda functions running on an AWS Greengrass Core. It will enable Lambda functions to invoke other Lambda functions deployed to the Greengrass Core, publish messages to the Greengrass Core and work with the local Shadow service.

Configuration

The AWS Greengrass Core SDK is used by Lambda functions that are running locally on the AWS Greengrass Core therefore there is no configuration required.

Using AWS Greengrass Core SDK

To use the AWS Greengrass Core SDK, you must first import the AWS Greengrass Core SDK in your Lambda function as you would with any other external libraries. You then need to create a client for 'iot-data' or 'lambda'. Use 'iot-data' if you wish to publish messages to the local AWS Greengrass Core and interact with the local Shadow service. Use 'lambda' if you wish to invoke other Lambda functions deployed to the same AWS Greengrass Core.

Here is an example for using the 'iot-data' client.

import greengrasssdk

# Let's instantiate the iot-data client
client = greengrasssdk.client('iot-data')

Now that you have an iot-data client, you can publish requests.

response = client.publish(
    topic='someTopic',
    payload='some data'.encode()
)

Here is an example for using the 'lambda' client.

import greengrasssdk

client = greengrasssdk.client('lambda')

Now that you have a lambda client, you can publish requests.


# Define the payload to pass to the invoked lambda function
msg = json.dumps({
    'message':"hello"
})


# Invoke the lambda function
response = client.invoke(
    FunctionName='arn:aws:lambda:<region>:<account id>:function:<function name>',
    InvocationType='RequestResponse',
    Payload=payload,
    Qualifier='2'
)

Implementation Recommendations

If you need to store and share data across multiple Lambda functions running on the AWS Greengrass Core, you can use the local Shadow service to store the information.

Compatibility

As new features are added to AWS Greengrass, previous versions of the Greengrass SDK will be incompatible with newer versions of the AWS Greengrass core. The following table lists the compatible SDKs for all GGC releases.

GGC Version Compatible SDK Versions
1.0.x-1.6.x 1.0.x-1.2.x
1.7.x 1.0.x-1.3.x

1.3.0 Updates

SDK supports SecretsManager client.

1.2.0 Updates

SDK and GGC compatibility check takes place in the background.

1.1.0 Updates

Lambda only accepted payload in JSON format. With this update, Invoking or publishing binary payload to a lambda is supported.