|
| 1 | +Greengrass SDK |
| 2 | +===================== |
| 3 | + |
| 4 | +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. |
| 5 | +You can find the latest, most up to date, documentation at our `doc site <http://aws-greengrass-core-sdk-python-docs.s3-website-us-east-1.amazonaws.com/v1.3.0/index.html>`_. |
| 6 | + |
| 7 | +=============================== |
| 8 | +Using AWS Greengrass Core SDK |
| 9 | +=============================== |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +Here is an example for using the 'iot-data' client |
| 14 | + |
| 15 | +.. code-block:: python |
| 16 | +
|
| 17 | + import greengrasssdk |
| 18 | +
|
| 19 | + # Let's instantiate the iot-data client |
| 20 | + client = greengrasssdk.client('iot-data') |
| 21 | +
|
| 22 | +
|
| 23 | +Now that you have an ``iot-data`` client, you can publish requests. |
| 24 | + |
| 25 | +.. code-block:: python |
| 26 | +
|
| 27 | + response = client.publish( |
| 28 | + topic='someTopic', |
| 29 | + payload='some data'.encode() |
| 30 | + ) |
| 31 | +
|
| 32 | +Here is an example for using the 'lambda' client. |
| 33 | + |
| 34 | +.. code-block:: python |
| 35 | +
|
| 36 | + import greengrasssdk |
| 37 | +
|
| 38 | + client = greengrasssdk.client('lambda') |
| 39 | +
|
| 40 | +Now that you have a lambda client, you can publish requests. |
| 41 | + |
| 42 | +.. code-block:: python |
| 43 | +
|
| 44 | + # Define the payload to pass to the invoked lambda function |
| 45 | + msg = json.dumps({ |
| 46 | + 'message':"hello" |
| 47 | + }) |
| 48 | +
|
| 49 | + # Invoke the lambda function |
| 50 | + response = client.invoke( |
| 51 | + FunctionName='arn:aws:lambda:<region>:<account id>:function:<function name>', |
| 52 | + InvocationType='RequestResponse', |
| 53 | + Payload=payload, |
| 54 | + Qualifier='2' |
| 55 | + ) |
| 56 | +
|
| 57 | +============== |
| 58 | +Compatibility |
| 59 | +============== |
| 60 | + |
| 61 | +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. |
| 62 | + |
| 63 | ++-------------+------------------------+ |
| 64 | +| GGC Version | Compatible SDK Versions| |
| 65 | ++=============+========================+ |
| 66 | +| 1.0.x-1.6.x | 1.0.x-1.2.x | |
| 67 | ++-------------+------------------------+ |
| 68 | +| 1.7.x | 1.0.x-1.3.x | |
| 69 | ++-------------+------------------------+ |
0 commit comments