Skip to content

Commit f242d01

Browse files
committed
Release of Version 1.3.0
1 parent 1865d02 commit f242d01

22 files changed

Lines changed: 1268 additions & 203 deletions

File tree

CHANGELOG.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=========
2+
CHANGELOG
3+
=========
4+
5+
1.3.0
6+
======
7+
8+
SDK supports SecretsManager client.
9+
10+
11+
1.2.0
12+
======
13+
14+
SDK and GGC compatibility check takes place in the background.
15+
16+
17+
1.1.0
18+
======
19+
Lambda only accepted payload in JSON format. With this update, Invoking or publishing binary payload to a lambda is supported.

LICENSE

Lines changed: 201 additions & 201 deletions
Large diffs are not rendered by default.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.txt *.py
2+
recursive-include *.txt *.py

README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
+-------------+------------------------+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
import sys
5+
import logging
6+
7+
# Setup logging to stdout
8+
logger = logging.getLogger(__name__)
9+
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
10+
11+
12+
def handler(event, context):
13+
logger.info('Invoked with payload ' + str(event))
14+
return 'Invoked successfully'
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
5+
# This example demonstrates invoking a lambda with 'binary' encoding type. In
6+
# order to run this example, remember to mark your 'invokee' lambda as a binary
7+
# lambda. You can configure this on the lambda configuration page in the
8+
# console. After the lambdas get deployed to your Greengrass Core, you should
9+
# be able to see 'Invoked successfully' returned by 'invokee' lambda. A lambda
10+
# function can support non-json payload, which is a new feature introduced in
11+
# GGC version 1.5.
12+
#
13+
import sys
14+
import base64
15+
import logging
16+
import json
17+
import greengrasssdk
18+
19+
# Setup logging to stdout
20+
logger = logging.getLogger(__name__)
21+
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
22+
23+
client = greengrasssdk.client('lambda')
24+
25+
26+
def handler(event, context):
27+
client_context = json.dumps({
28+
'custom': 'custom text'
29+
})
30+
31+
try:
32+
response = client.invoke(
33+
ClientContext=base64.b64encode(bytes(client_context)),
34+
FunctionName='arn:aws:lambda:<region>:<accountId>:function:<targetFunctionName>:<targetFunctionQualifier>',
35+
InvocationType='RequestResponse',
36+
Payload='Non-JSON Data',
37+
Qualifier='1'
38+
)
39+
40+
logger.info(response['Payload'].read())
41+
except Exception as e:
42+
logger.error(e)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
# Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
5+
# greengrassHelloWorld.py
6+
# Demonstrates a simple publish to a topic using Greengrass core sdk
7+
# This lambda function will retrieve underlying platform information and send
8+
# a hello world message along with the platform information to the topic
9+
# 'hello/world'. The function will sleep for five seconds, then repeat.
10+
# Since the function is long-lived it will run forever when deployed to a
11+
# Greengrass core. The handler will NOT be invoked in our example since
12+
# the we are executing an infinite loop.
13+
14+
import greengrasssdk
15+
import platform
16+
from threading import Timer
17+
18+
19+
# Creating a greengrass core sdk client
20+
client = greengrasssdk.client('iot-data')
21+
22+
# Retrieving platform information to send from Greengrass Core
23+
my_platform = platform.platform()
24+
25+
26+
# When deployed to a Greengrass core, this code will be executed immediately
27+
# as a long-lived lambda function. The code will enter the infinite while
28+
# loop below.
29+
# If you execute a 'test' on the Lambda Console, this test will fail by
30+
# hitting the execution timeout of three seconds. This is expected as
31+
# this function never returns a result.
32+
33+
def greengrass_hello_world_run():
34+
if not my_platform:
35+
client.publish(
36+
topic='hello/world',
37+
payload='Hello world! Sent from Greengrass Core.')
38+
else:
39+
client.publish(
40+
topic='hello/world',
41+
payload='Hello world! Sent from '
42+
'Greengrass Core running on platform: {}'
43+
.format(my_platform))
44+
45+
# Asynchronously schedule this function to be run again in 5 seconds
46+
Timer(5, greengrass_hello_world_run).start()
47+
48+
49+
# Start executing the function above
50+
greengrass_hello_world_run()
51+
52+
53+
# This is a dummy handler and will not be invoked
54+
# Instead the code above will be executed in an infinite loop for our example
55+
def function_handler(event, context):
56+
return
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
5+
import sys
6+
import logging
7+
import greengrasssdk
8+
9+
# Setup logging to stdout
10+
logger = logging.getLogger(__name__)
11+
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
12+
13+
client = greengrasssdk.client('iot-data')
14+
15+
16+
def message_handler(event, context):
17+
logger.info("Received message!")
18+
if 'state' in event:
19+
if event['state'] == "on":
20+
client.update_thing_shadow(
21+
thingName="RobotArm_Thing",
22+
payload='{"state":{"desired":{"myState":"on"}}}')
23+
logger.info("Triggering publish to shadow "
24+
"topic to set state to ON")
25+
elif event['state'] == "off":
26+
client.update_thing_shadow(
27+
thingName="RobotArm_Thing",
28+
payload='{"state":{"desired":{"myState":"off"}}}')
29+
logger.info("Triggering publish to shadow "
30+
"topic to set state to OFF")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
5+
import sys
6+
import logging
7+
import greengrasssdk
8+
9+
# Setup logging to stdout
10+
logger = logging.getLogger(__name__)
11+
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
12+
13+
client = greengrasssdk.client('iot-data')
14+
15+
16+
def uptime_handler(event, context):
17+
logger.info("Received message!")
18+
if 'state' in event:
19+
if event['state'] == "on":
20+
client.publish(
21+
topic='/topic/metering',
22+
payload="Robot arm turned ON")
23+
logger.info("Triggering publish to topic "
24+
"/topic/metering with ON state")
25+
elif event['state'] == "off":
26+
client.publish(
27+
topic='/topic/metering',
28+
payload="Robot arm turned OFF")
29+
logger.info("Triggering publish to topic "
30+
"/topic/metering with OFF state")

0 commit comments

Comments
 (0)