Skip to content

Commit 909dce7

Browse files
Updated README
1 parent 80640e1 commit 909dce7

File tree

1 file changed

+50
-19
lines changed

1 file changed

+50
-19
lines changed

README.md

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
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

514
This 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.
6170
First, you'll need to install the AWS CDK if you haven't already. The CDK requires Node.js and npm to run.
6271
See the [Getting started with the AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html) for
6372
more details.
64-
65-
`npm install -g aws-cdk`
73+
```bash
74+
npm install -g aws-cdk
75+
```
76+
6677

6778
Next 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
7586
https://pipenv.pypa.io/en/latest/install/
7687

7788
Then you can use pipenv to install all the Python dependencies.
78-
79-
`pipenv install`
89+
```
90+
pipenv install
91+
```
8092

8193
Once 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

89104
Once the dependencies are installed, to work with the CDK and deploy your application, you'll need to change directories
90105
to the ``infrastructure`` directory.
91106

92107
1. 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
96113
2. Now you're ready to deploy your application.
97-
98-
`cdk deploy`
114+
```
115+
cdk deploy
116+
```
99117
100118
Note: During deployment, the CDK will ask you to approve of the changes being created by CloudFormation, make sure to
101119
type `y` when prompted.
@@ -104,7 +122,9 @@ type `y` when prompted.
104122
and 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
133153
1. Download the AWS IoT CA server certificate from [here](https://www.amazontrust.com/repository/AmazonRootCA1.pem) and
134154
store 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
138160
2. Make sure the correct environment variables mentioned above are configured. The exact commands to do
139161
this might vary slightly between operating systems and runtime environments. But generally in standard Linux/Unix shells
140162
it's accomplished by running `$ export <KEY>=<VALUE>` for each environment variable.
141163
142164
3. 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
148172
1. 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
152177
2. 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:
179206
2. You will need to make a "GET" request to the registration API to get a token. When this request is made, the API will
180207
generate a token as well as dummy metadata including "tenant", "location", "deviceType", and save it all to a DynamoDB table.
181208
The 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
184213
3. Copy the token out of the response from the previous request and use it to create a "POST" request to the local IoT client.
185214
Please note the token expires in 5 minutes. The URL for this request is `127.0.0.1:5000/regToken`.
186215
The 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
190221
The registration token will then be used by the Registration API to authenticate the device and retrieve a certificate
191222
issued by AWS IoT Core. Once The IoT client has the certificate, and the device has been registered, it will complete

0 commit comments

Comments
 (0)