|
1 |
| -## AWS IoT SDK for Python v2 |
| 1 | +# AWS IoT SDK for Python v2 |
2 | 2 |
|
3 |
| -Next generation AWS IoT Client SDK for Python using the AWS Common Runtime |
| 3 | +Next generation AWS IoT Client SDK for Python. |
4 | 4 |
|
5 |
| -## License |
| 5 | +This SDK is built on the AWS Common Runtime, a collection of libraries |
| 6 | +([1](https://github.com/awslabs/aws-c-common), |
| 7 | +[2](https://github.com/awslabs/aws-c-io), |
| 8 | +[3](https://github.com/awslabs/aws-c-mqtt), ...) written in C to be |
| 9 | +cross-platform, high-performance, secure, and reliable. The libraries are bound |
| 10 | +to Python by the [awscrt](https://github.com/awslabs/aws-crt-python) package. |
6 | 11 |
|
7 |
| -This library is licensed under the Apache 2.0 License. |
| 12 | +Integration with AWS IoT Services such as |
| 13 | +[Device Shadow](https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html) |
| 14 | +and [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html) |
| 15 | +is provided by code that been generated from a model of the service. |
| 16 | + |
| 17 | +# Installation |
| 18 | +## Minimum Requirements |
| 19 | +* Python 3.5+ or Python 2.7+ |
| 20 | +* CMake 3.1+ |
| 21 | +* Clang 3.9+ or GCC 4.4+ or MSVC 2015+ |
| 22 | + |
| 23 | +## Build from source |
| 24 | +``` |
| 25 | +git clone https://github.com/awslabs/aws-crt-python.git --recursive |
| 26 | +git clone https://github.com/awslabs/aws-iot-device-sdk-python-v2.git |
| 27 | +pip install ./aws-crt-python |
| 28 | +pip install ./aws-iot-device-sdk-python-v2 |
| 29 | +``` |
| 30 | + |
| 31 | +# Samples |
| 32 | + |
| 33 | +## pubsub |
| 34 | +This sample uses the Message Broker for AWS IoT to send and receive messages |
| 35 | +through an MQTT connection. On startup, the device connects to the server, |
| 36 | +subscribes to a topic, and begins publishing messages to that topic. |
| 37 | +The device should receive those same messages back from the message broker, |
| 38 | +since it is subscribed to that same topic. |
| 39 | +Status updates are continually printed to the console. |
| 40 | + |
| 41 | +Source: `samples/pubsub.py` |
| 42 | + |
| 43 | +Run the sample like this: |
| 44 | +``` |
| 45 | +python pubsub.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> |
| 46 | +``` |
| 47 | + |
| 48 | +Your Thing's |
| 49 | +[Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) |
| 50 | +must provide privileges for this sample to connect, subscribe, publish, |
| 51 | +and receive. The Policy document should look something like this: |
| 52 | + |
| 53 | +<pre> |
| 54 | +{ |
| 55 | + "Version": "2012-10-17", |
| 56 | + "Statement": [ |
| 57 | + { |
| 58 | + "Effect": "Allow", |
| 59 | + "Action": [ |
| 60 | + "iot:Publish", |
| 61 | + "iot:Receive" |
| 62 | + ], |
| 63 | + "Resource": [ |
| 64 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topic/samples/test" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "Effect": "Allow", |
| 69 | + "Action": [ |
| 70 | + "iot:Subscribe" |
| 71 | + ], |
| 72 | + "Resource": [ |
| 73 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topicfilter/samples/test" |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "Effect": "Allow", |
| 78 | + "Action": [ |
| 79 | + "iot:Connect" |
| 80 | + ], |
| 81 | + "Resource": [ |
| 82 | + "arn:aws:iot:<b>region</b>:<b>account</b>:client/samples-client-id" |
| 83 | + ] |
| 84 | + } |
| 85 | + ] |
| 86 | +} |
| 87 | +</pre> |
| 88 | + |
| 89 | +## shadow |
| 90 | + |
| 91 | +This sample uses the AWS IoT Device Shadow Service to keep a property in |
| 92 | +sync between device and server. Imagine a light whose color may be changed |
| 93 | +through an app, or set by a local user. |
| 94 | + |
| 95 | +Once connected, type a value in the terminal and press Enter to update |
| 96 | +the property's "reported" value. The sample also responds when the "desired" |
| 97 | +value changes on the server. To observe this, edit the Shadow document in |
| 98 | +the AWS Console and set a new "desired" value. |
| 99 | + |
| 100 | +On startup, the sample requests the shadow document to learn the property's |
| 101 | +initial state. The sample also subscribes to "delta" events from the server, |
| 102 | +which are sent when a property's "desired" value differs from its "reported" |
| 103 | +value. When the sample learns of a new desired value, that value is changed |
| 104 | +on the device and an update is sent to the server with the new "reported" |
| 105 | +value. |
| 106 | + |
| 107 | +Source: `samples/shadow.py` |
| 108 | + |
| 109 | +Run the sample like this: |
| 110 | +``` |
| 111 | +python shadow.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name> |
| 112 | +``` |
| 113 | + |
| 114 | +Your Thing's |
| 115 | +[Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) |
| 116 | +must provide privileges for this sample to connect, subscribe, publish, |
| 117 | +and receive. The Policy document should look something like this: |
| 118 | + |
| 119 | +<pre> |
| 120 | +{ |
| 121 | + "Version": "2012-10-17", |
| 122 | + "Statement": [ |
| 123 | + { |
| 124 | + "Effect": "Allow", |
| 125 | + "Action": [ |
| 126 | + "iot:Publish" |
| 127 | + ], |
| 128 | + "Resource": [ |
| 129 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/things/<b>thingname</b>/shadow/get", |
| 130 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/things/<b>thingname</b>/shadow/update" |
| 131 | + ] |
| 132 | + }, |
| 133 | + { |
| 134 | + "Effect": "Allow", |
| 135 | + "Action": [ |
| 136 | + "iot:Receive" |
| 137 | + ], |
| 138 | + "Resource": [ |
| 139 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/things/<b>thingname</b>/shadow/get/accepted", |
| 140 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/things/<b>thingname</b>/shadow/get/rejected", |
| 141 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/things/<b>thingname</b>/shadow/update/accepted", |
| 142 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/things/<b>thingname</b>/shadow/update/rejected", |
| 143 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/things/<b>thingname</b>/shadow/update/delta" |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "Effect": "Allow", |
| 148 | + "Action": [ |
| 149 | + "iot:Subscribe" |
| 150 | + ], |
| 151 | + "Resource": [ |
| 152 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topicfilter/$aws/things/<b>thingname</b>/shadow/get/accepted", |
| 153 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topicfilter/$aws/things/<b>thingname</b>/shadow/get/rejected", |
| 154 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topicfilter/$aws/things/<b>thingname</b>/shadow/update/accepted", |
| 155 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topicfilter/$aws/things/<b>thingname</b>/shadow/update/rejected", |
| 156 | + "arn:aws:iot:<b>region</b>:<b>account</b>:topicfilter/$aws/things/<b>thingname</b>/shadow/update/delta" |
| 157 | + ] |
| 158 | + }, |
| 159 | + { |
| 160 | + "Effect": "Allow", |
| 161 | + "Action": "iot:Connect", |
| 162 | + "Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/samples-client-id" |
| 163 | + } |
| 164 | + ] |
| 165 | +} |
| 166 | +</pre> |
| 167 | +# License |
| 168 | + |
| 169 | +This library is licensed under the Apache 2.0 License. |
0 commit comments