Skip to content

Commit 7ceb5e5

Browse files
authored
Fleet provisioning docs (#213)
* Update days before close to 4 days so it matches github tag description Reduce bot run frequency to once a day * Fix fleep provisioning cli command and format readme to be more uniform * add sh tags to code segments * fix spacing and newlines * format command line instructions into a more readable format * Update README.md
1 parent f107ecf commit 7ceb5e5

File tree

3 files changed

+105
-67
lines changed

3 files changed

+105
-67
lines changed

.github/workflows/stale-issue.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: "Close stale issues"
33
# Controls when the action will run.
44
on:
55
schedule:
6-
- cron: "*/60 * * * *"
6+
- cron: "0 0 * * *"
77

88
jobs:
99
cleanup:

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ to Python by the `awscrt` package ([PyPI](https://pypi.org/project/awscrt/)) ([G
2626
* [Samples](samples)
2727
* [Getting Help](#Getting-Help)
2828
* [Giving Feedback and Contributions](#Giving-Feedback-and-Contributions)
29+
* [More Resources](#More-Resources)
30+
2931

3032
## Installation
3133

@@ -56,6 +58,7 @@ sudo apt-get install cmake
5658
sudo apt-get install python3-dev
5759
```
5860

61+
5962
## Mac-Only TLS Behavior
6063

6164
Please note that on Mac, once a private key is used with a certificate, that certificate-key pair is imported into the Mac Keychain. All subsequent uses of that certificate will use the stored private key and ignore anything passed in programmatically. Beginning in v1.3.2, when a stored private key from the Keychain is used, the following will be logged at the "info" log level:
@@ -64,6 +67,7 @@ Please note that on Mac, once a private key is used with a certificate, that cer
6467
static: certificate has an existing certificate-key pair that was previously imported into the Keychain. Using key from Keychain instead of the one provided.
6568
```
6669

70+
6771
## Samples
6872

6973
[Samples README](samples)
@@ -88,10 +92,24 @@ is provided by code that been generated from a model of the service.
8892

8993
We need your help in making this SDK great. Please participate in the community and contribute to this effort by submitting issues, participating in discussion forums and submitting pull requests through the following channels.
9094

91-
* [Contributions Guidelines](CONTRIBUTING.md)
95+
* [Contributions Guidelines](/CONTRIBUTING.md)
9296
* Articulate your feature request or upvote existing ones on our [Issues](https://github.com/aws/aws-iot-device-sdk-python-v2/issues?q=is%3Aissue+is%3Aopen+label%3Afeature-request) page.
9397
* Submit [Issues](https://github.com/aws/aws-iot-device-sdk-python-v2/issues)
9498

95-
# License
99+
100+
## More Resources
101+
102+
* [AWS IoT Core Documentation](https://docs.aws.amazon.com/iot/)
103+
* [Developer Guide](https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html) ([source](https://github.com/awsdocs/aws-iot-docs))
104+
* [Issues](https://github.com/aws/aws-iot-device-sdk-python-v2/issues)
105+
* [Dev Blog](https://aws.amazon.com/blogs/?awsf.blog-master-iot=category-internet-of-things%23amazon-freertos%7Ccategory-internet-of-things%23aws-greengrass%7Ccategory-internet-of-things%23aws-iot-analytics%7Ccategory-internet-of-things%23aws-iot-button%7Ccategory-internet-of-things%23aws-iot-device-defender%7Ccategory-internet-of-things%23aws-iot-device-management%7Ccategory-internet-of-things%23aws-iot-platform)
106+
107+
Integration with AWS IoT Services such as
108+
[Device Shadow](https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html)
109+
and [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html)
110+
is provided by code that been generated from a model of the service.
111+
112+
113+
## License
96114

97115
This library is licensed under the Apache 2.0 License.

samples/README.md

Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* [basic discovery](#basic-discovery)
77
* [IPC with AWS IoT Greengrass to publish to AWS IoT Core](#ipc-with-aws-iot-greengrass-to-publish-to-aws-iot-core)
88

9-
## pubsub
9+
## Pubsub
10+
1011
This sample uses the
1112
[Message Broker](https://docs.aws.amazon.com/iot/latest/developerguide/iot-message-broker.html)
1213
for AWS IoT to send and receive messages
@@ -19,7 +20,7 @@ Status updates are continually printed to the console.
1920
Source: `samples/pubsub.py`
2021

2122
Run the sample like this:
22-
```
23+
``` sh
2324
python3 pubsub.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file>
2425
```
2526

@@ -67,7 +68,7 @@ and receive.
6768
</pre>
6869
</details>
6970

70-
## shadow
71+
## Shadow
7172

7273
This sample uses the AWS IoT
7374
[Device Shadow](https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html)
@@ -90,7 +91,7 @@ value.
9091
Source: `samples/shadow.py`
9192

9293
Run the sample like this:
93-
```
94+
``` sh
9495
python3 shadow.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
9596
```
9697

@@ -151,7 +152,7 @@ and receive.
151152
</pre>
152153
</details>
153154

154-
## jobs
155+
## Jobs
155156

156157
This sample uses the AWS IoT
157158
[Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html)
@@ -176,7 +177,7 @@ sample will be continually prompted to try another job until none remain.
176177
Source: `samples/jobs.py`
177178

178179
Run the sample like this:
179-
```
180+
``` sh
180181
python3 jobs.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
181182
```
182183

@@ -236,7 +237,7 @@ and receive.
236237
</pre>
237238
</details>
238239

239-
## fleet provisioning
240+
## Fleet Provisioning
240241

241242
This sample uses the AWS IoT
242243
[Fleet provisioning](https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html)
@@ -248,12 +249,12 @@ publishes the request to corresponding topic and calls RegisterThing.
248249
Source: `samples/fleetprovisioning.py`
249250

250251
Run the sample using createKeysAndCertificate:
251-
```
252+
``` sh
252253
python3 fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters>
253254
```
254255

255256
Run the sample using createCertificateFromCsr:
256-
```
257+
``` sh
257258
python3 fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters> --csr <csr file>
258259
```
259260

@@ -304,102 +305,121 @@ and receive.
304305
</pre>
305306
</details>
306307

307-
#### Fleet Provisioning Detailed Instructions
308+
### Fleet Provisioning Detailed Instructions
308309

309-
##### Aws Resource Setup
310-
Fleet provisioning requires some additional AWS resources be set up first. This section documents the steps you need to take to
311-
get the sample up and running. These steps assume you have the AWS CLI installed and the default user/credentials has
312-
sufficient permission to perform all of the listed operations. These steps are based on provisioning setup steps
313-
that can be found at [Embedded C SDK Setup](https://docs.aws.amazon.com/freertos/latest/lib-ref/c-sdk/provisioning/provisioning_tests.html#provisioning_system_tests_setup)
310+
#### Aws Resource Setup
314311

315-
First, create the IAM role that will be needed by the fleet provisioning template. Replace `RoleName` with a name of the role you want to create.
316-
<pre>
312+
Fleet provisioning requires some additional AWS resources be set up first. This section documents the steps you need to take to
313+
get the sample up and running. These steps assume you have the AWS CLI installed and the default user/credentials has
314+
sufficient permission to perform all of the listed operations. These steps are based on provisioning setup steps
315+
that can be found at [Embedded C SDK Setup](https://docs.aws.amazon.com/freertos/latest/lib-ref/c-sdk/provisioning/provisioning_tests.html#provisioning_system_tests_setup).
316+
317+
First, create the IAM role that will be needed by the fleet provisioning template. Replace `RoleName` with a name of the role you want to create.
318+
``` sh
317319
aws iam create-role \
318320
--role-name [RoleName] \
319321
--assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Action":"sts:AssumeRole","Effect":"Allow","Principal":{"Service":"iot.amazonaws.com"}}]}'
320-
</pre>
322+
```
321323
Next, attach a policy to the role created in the first step. Replace `RoleName` with the name of the role you created previously.
322-
<pre>
324+
``` sh
323325
aws iam attach-role-policy \
324326
--role-name [RoleName] \
325327
--policy-arn arn:aws:iam::aws:policy/service-role/AWSIoTThingsRegistration
326-
</pre>
327-
Finally, create the template resource which will be used for provisioning by the demo application. This needs to be done only
328-
once. To create a template, the following AWS CLI command may be used. Replace `TemplateName` with the name of the fleet
329-
provisioning template you want to create. Replace `RoleName` with the name of the role you created previously. Replace
330-
`TemplateJSON` with the template body as a JSON string (containing escape characters). Replace `account` with your AWS
331-
account number.
332-
<pre>
328+
```
329+
Finally, create the template resource which will be used for provisioning by the demo application. This needs to be done only
330+
once. To create a template, the following AWS CLI command may be used. Replace `TemplateName` with the name of the fleet
331+
provisioning template you want to create. Replace `RoleName` with the name of the role you created previously. Replace
332+
`TemplateJSON` with the template body as a JSON string (containing escape characters). Replace `account` with your AWS
333+
account number.
334+
``` sh
333335
aws iot create-provisioning-template \
334336
--template-name [TemplateName] \
335-
--provisioning-role-arn arn:aws:iam::[account]:service-role/[RoleName] \
337+
--provisioning-role-arn arn:aws:iam::[account]:role/[RoleName] \
336338
--template-body "[TemplateJSON]" \
337-
--enabled
338-
</pre>
339+
--enabled
340+
```
339341
The rest of the instructions assume you have used the following for the template body:
340-
<pre>
342+
``` sh
341343
{\"Parameters\":{\"DeviceLocation\":{\"Type\":\"String\"},\"AWS::IoT::Certificate::Id\":{\"Type\":\"String\"},\"SerialNumber\":{\"Type\":\"String\"}},\"Mappings\":{\"LocationTable\":{\"Seattle\":{\"LocationUrl\":\"https://example.aws\"}}},\"Resources\":{\"thing\":{\"Type\":\"AWS::IoT::Thing\",\"Properties\":{\"ThingName\":{\"Fn::Join\":[\"\",[\"ThingPrefix_\",{\"Ref\":\"SerialNumber\"}]]},\"AttributePayload\":{\"version\":\"v1\",\"serialNumber\":\"serialNumber\"}},\"OverrideSettings\":{\"AttributePayload\":\"MERGE\",\"ThingTypeName\":\"REPLACE\",\"ThingGroups\":\"DO_NOTHING\"}},\"certificate\":{\"Type\":\"AWS::IoT::Certificate\",\"Properties\":{\"CertificateId\":{\"Ref\":\"AWS::IoT::Certificate::Id\"},\"Status\":\"Active\"},\"OverrideSettings\":{\"Status\":\"REPLACE\"}},\"policy\":{\"Type\":\"AWS::IoT::Policy\",\"Properties\":{\"PolicyDocument\":{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"iot:Connect\",\"iot:Subscribe\",\"iot:Publish\",\"iot:Receive\"],\"Resource\":\"*\"}]}}}},\"DeviceConfiguration\":{\"FallbackUrl\":\"https://www.example.com/test-site\",\"LocationUrl\":{\"Fn::FindInMap\":[\"LocationTable\",{\"Ref\":\"DeviceLocation\"},\"LocationUrl\"]}}}
342-
</pre>
344+
```
343345
If you use a different body, you may need to pass in different template parameters.
344-
##### Running the sample and provisioning using a certificate-key set from a provisioning claim
345346

346-
To run the provisioning sample, you'll need a certificate and key set with sufficient permissions. Provisioning certificates are normally
347-
created ahead of time and placed on your device, but for this sample, we will just create them on the fly. You can also
347+
#### Running the sample and provisioning using a certificate-key set from a provisioning claim
348+
349+
To run the provisioning sample, you'll need a certificate and key set with sufficient permissions. Provisioning certificates are normally
350+
created ahead of time and placed on your device, but for this sample, we will just create them on the fly. You can also
348351
use any certificate set you've already created if it has sufficient IoT permissions and in doing so, you can skip the step
349352
that calls `create-provisioning-claim`.
350353

351354
We've included a script in the utils folder that creates certificate and key files from the response of calling
352-
`create-provisioning-claim`. These dynamically sourced certificates are only valid for five minutes. When running the command,
355+
`create-provisioning-claim`. These dynamically sourced certificates are only valid for five minutes. When running the command,
353356
you'll need to substitute the name of the template you previously created, and on Windows, replace the paths with something appropriate.
354357

355358
(Optional) Create a temporary provisioning claim certificate set:
356-
<pre>
357-
aws iot create-provisioning-claim --template-name [TemplateName] | python3 ../utils/parse_cert_set_result.py --path /tmp --filename provision
358-
</pre>
359+
``` sh
360+
aws iot create-provisioning-claim \
361+
--template-name [TemplateName] \
362+
| python3 ../utils/parse_cert_set_result.py \
363+
--path /tmp \
364+
--filename provision
365+
```
359366

360-
The provisioning claim's cert and key set have been written to `/tmp/provision*`. Now you can use these temporary keys
361-
to perform the actual provisioning. If you are not using the temporary provisioning certificate, replace the paths for `--cert`
367+
The provisioning claim's cert and key set have been written to `/tmp/provision*`. Now you can use these temporary keys
368+
to perform the actual provisioning. If you are not using the temporary provisioning certificate, replace the paths for `--cert`
362369
and `--key` appropriately:
363370

364-
<pre>
365-
python3 fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}"
366-
</pre>
371+
``` sh
372+
python3 fleetprovisioning.py \
373+
--endpoint [your endpoint]-ats.iot.[region].amazonaws.com \
374+
--root-ca [pathToRootCA] \
375+
--cert /tmp/provision.cert.pem \
376+
--key /tmp/provision.private.key \
377+
--templateName [TemplateName] \
378+
--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}"
379+
```
367380

368381
Notice that we provided substitution values for the two parameters in the template body, `DeviceLocation` and `SerialNumber`.
369382

370-
##### Run the sample using the certificate signing request workflow
383+
#### Run the sample using the certificate signing request workflow
384+
371385
To run the sample with this workflow, you'll need to create a certificate signing request.
372386

373387
First create a certificate-key pair:
374-
<pre>
388+
``` sh
375389
openssl genrsa -out /tmp/deviceCert.key 2048
376-
</pre>
390+
```
377391

378392
Next create a certificate signing request from it:
379-
<pre>
393+
``` sh
380394
openssl req -new -key /tmp/deviceCert.key -out /tmp/deviceCert.csr
381-
</pre>
395+
```
382396

383-
(Optional) As with the previous workflow, we'll create a temporary certificate set from a provisioning claim. This step can
397+
(Optional) As with the previous workflow, we'll create a temporary certificate set from a provisioning claim. This step can
384398
be skipped if you're using a certificate set capable of provisioning the device:
385399

386-
<pre>
387-
aws iot create-provisioning-claim --template-name [TemplateName] | python3 ../utils/parse_cert_set_result.py --path /tmp --filename provision
388-
</pre>
400+
``` sh
401+
aws iot create-provisioning-claim \
402+
--template-name [TemplateName] \
403+
| python3 ../utils/parse_cert_set_result.py \
404+
--path /tmp \
405+
--filename provision
406+
```
389407

390-
Finally, supply the certificate signing request while invoking the provisioning sample. As with the previous workflow, if
408+
Finally, supply the certificate signing request while invoking the provisioning sample. As with the previous workflow, if
391409
using a permanent certificate set, replace the paths specified in the `--cert` and `--key` arguments:
392-
<pre>
393-
python3 fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}" --csr /tmp/deviceCert.csr
394-
</pre>
395410

396-
## basic discovery
397-
398-
This sample is intended for use directly with the
399-
[Getting Started with AWS IoT Greengrass](https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-gs.html) guide.
400-
401-
## IPC with AWS IoT Greengrass to publish to AWS IoT Core
411+
``` sh
412+
python3 fleetprovisioning.py \
413+
--endpoint [your endpoint]-ats.iot.[region].amazonaws.com \
414+
--root-ca [pathToRootCA] \
415+
--cert /tmp/provision.cert.pem \
416+
--key /tmp/provision.private.key \
417+
--templateName [TemplateName] \
418+
--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}" \
419+
--csr /tmp/deviceCert.csr
420+
```
402421

403-
This sample is intended to be deployed as an AWS IoT Greengrass component and it will publish MQTT messages from the device to AWS IoT Core.
422+
## Greengrass Discovery
404423

405-
Source: `samples/ipc_greengrass.py`
424+
This sample intended for use directly with the
425+
[Getting Started with AWS IoT Greengrass](https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-gs.html) guide.

0 commit comments

Comments
 (0)