11# Device Provisioning via Sideloaded Registration Codes
22
3+ ## Table of contents
4+ * [ Summary] ( #summary )
5+ * [ Set Up] ( #set-up )
6+ * [ Demo] ( #demo )
7+ * [ Cleanup] ( #cleanup )
8+ * [ Security] ( #security )
9+ * [ License] ( #license )
10+
11+
312## Summary
413
514This sample provides an end-to-end demo of using a single-use, short expiry registration code to provision devices by
@@ -61,8 +70,10 @@ directory.
6170First, you'll need to install the AWS CDK if you haven't already. The CDK requires Node.js and npm to run.
6271See the [ Getting started with the AWS CDK] ( https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html ) for
6372more details.
64-
65- `npm install -g aws-cdk`
73+ ``` bash
74+ npm install -g aws-cdk
75+ ```
76+
6677
6778Next you'll need to install the dependencies for the CDK deployment.
6879
@@ -75,27 +86,34 @@ with the repo that you can use to install all dependencies to run the client. Fi
7586https://pipenv.pypa.io/en/latest/install/
7687
7788Then you can use pipenv to install all the Python dependencies.
78-
79- `pipenv install`
89+ ```
90+ pipenv install
91+ ```
8092
8193Once all dependencies are installed, you'll need to activate the shell with ` pipenv shell `
8294
8395#### Installing Dependencies Globally
8496
85- From the root directory, switch to the ` api ` directory with ` cd api ` and then run ` pip install -r requirements.txt `
97+ From the root directory, switch to the ` api ` directory with ` cd api ` and then run
98+ ```
99+ pip install -r requirements.txt
100+ ```
86101
87102### Deploying Code
88103
89104Once the dependencies are installed, to work with the CDK and deploy your application, you'll need to change directories
90105to the `` infrastructure `` directory.
91106
921071 . If this is you're first time using the CDK you'll need to bootstrap your AWS account with the resouces the CDK needs.
93-
94- ` cdk bootstrap `
108+ ```
109+ cdk bootstrap
110+ ```
111+
95112
961132. Now you're ready to deploy your application.
97-
98- ` cdk deploy `
114+ ```
115+ cdk deploy
116+ ```
99117
100118Note: During deployment, the CDK will ask you to approve of the changes being created by CloudFormation, make sure to
101119type `y` when prompted.
@@ -104,7 +122,9 @@ type `y` when prompted.
104122and that's the AWS IoT Credential Provider role alias and the AWS IoT Thing Types.
105123
106124 1. The creation of the role alias can not be done via the console and must be done via a CLI command:
107- `aws iot create-role-alias --role-alias <tenant> --role-arn <Role arn from CDK template>`
125+ ```
126+ aws iot create-role-alias --role-alias <tenant> --role-arn <Role arn from CDK template>
127+ ```
108128 You'll be using a fake "tenant" as the role alias name. In our case, that tenant name is `acme`.
109129 The role arn should come from the `AWSIoTCredentialProviderRole` role that was deployed with the CloudFormation template.
110130
@@ -132,26 +152,33 @@ A sample Docker environment file has been included if you choose to run the clie
132152
1331531. Download the AWS IoT CA server certificate from [here](https://www.amazontrust.com/repository/AmazonRootCA1.pem) and
134154store it in the `client` directory. This will be used by the IoT client to trust the AWS IoT Core Device Gateway.
155+ ```
156+ wget -O client/AmazonRootCA1.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem
157+ ```
135158
136- `wget -O client/AmazonRootCA1.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem`
137159
1381602. Make sure the correct environment variables mentioned above are configured. The exact commands to do
139161this might vary slightly between operating systems and runtime environments. But generally in standard Linux/Unix shells
140162it's accomplished by running `$ export <KEY>=<VALUE>` for each environment variable.
141163
1421643. With environment variables set, you're ready to start the client. The Python client requires no arguments passed to it.
143-
144- ` python iot_client.py `
165+ ```
166+ python iot_client.py
167+ ```
168+
145169
146170#### Option B - Running in Docker
147171
1481721. For running with docker, you'll need to build the container locally using the included Dockerfile.
149-
150- ` docker build -t <use any image tag name here> . `
173+ ```
174+ docker build -t <use any image tag name here> .
175+ ```
151176
1521772. Make sure the previously mentioned environment file has the correct values set and then `docker run` with the following command:
178+ ```
179+ docker run -p 5000:5000 --env-file docker.env -it <build-image-tag>
180+ ```
153181
154- ` docker run -p 5000:5000 --env-file docker.env -it <image tag> `
155182
156183## Demo
157184
@@ -179,13 +206,17 @@ The overview of the demo steps are as follows:
1792062. You will need to make a "GET" request to the registration API to get a token. When this request is made, the API will
180207generate a token as well as dummy metadata including "tenant", "location", "deviceType", and save it all to a DynamoDB table.
181208The URL for the request is: <Registration API endpoint from CloudFormation stack>/api/token
182- ` curl <endpoint>/api/token `
209+ ```
210+ curl <REGISTRATION_API_ENDPOINT>/api/token
211+ ```
183212
1842133. Copy the token out of the response from the previous request and use it to create a "POST" request to the local IoT client.
185214Please note the token expires in 5 minutes. The URL for this request is `127.0.0.1:5000/regToken`.
186215The body should be JSON and the structure is: `{"registrationCode": "<value>"}`
187-
188- `curl --request POST '127.0.0.1:5000/regToken' --header 'Content-Type: application/json' --data-raw '{"registrationCode": <token from previous request>}'`
216+ ```
217+ curl --request POST '127.0.0.1:5000/regToken' --header 'Content-Type: application/json' --data-raw '{"registrationCode": <token from previous request>}'
218+ ```
219+
189220
190221The registration token will then be used by the Registration API to authenticate the device and retrieve a certificate
191222issued by AWS IoT Core. Once The IoT client has the certificate, and the device has been registered, it will complete
0 commit comments