Skip to content

Commit 269c2eb

Browse files
zayeshaatawsJustin Boswell
andauthored
Fleetprovisioning (#55)
* Fleet provisioning * Updated to aws-crt-java v0.5.6 Co-authored-by: Justin Boswell <[email protected]>
1 parent ea263af commit 269c2eb

16 files changed

+1128
-6
lines changed

README.md

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## AWS IoT SDK for Java v2
22

3+
34
Next generation AWS IoT Client SDK for Java using the AWS Common Runtime
45

56
This project is in **GENERAL AVAILABILITY**. If you have any issues or feature
@@ -18,13 +19,20 @@ to Java by the [aws-crt-java](https://github.com/awslabs/aws-crt-java) package.
1819

1920
Integration with AWS IoT Services such as
2021
[Device Shadow](https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html)
21-
and [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html)
22+
[Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html)
23+
[Fleet Provisioning](https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html)
2224
is provided by code that been generated from a model of the service.
2325

2426
# Installation
2527
## Minimum Requirements
2628
* Java 8 or above
27-
* Maven
29+
30+
** Set JAVA_HOME first
31+
32+
* Install Maven
33+
34+
brew install maven
35+
2836
## Requirements to build the AWS CRT locally
2937
* CMake 3.1+
3038
* Clang 3.9+ or GCC 4.4+ or MSVC 2015+
@@ -34,18 +42,20 @@ is provided by code that been generated from a model of the service.
3442
git clone https://github.com/awslabs/aws-iot-device-sdk-java-v2.git
3543
# update the version of the CRT being used
3644
mvn versions:use-latest-versions -Dincludes="software.amazon.awssdk.crt*"
37-
mvn install
45+
mvn clean install
3846
```
3947

4048
## Build CRT from source
4149
```sh
4250
# NOTE: use the latest version of the CRT here
43-
git clone --branch v0.5.4 https://github.com/awslabs/aws-crt-java.git
51+
52+
git clone --branch v0.4.20 https://github.com/awslabs/aws-crt-java.git
53+
4454
git clone https://github.com/awslabs/aws-iot-device-sdk-java-v2.git
4555
cd aws-crt-java
4656
mvn install -Dmaven.test.skip=true
4757
cd ../aws-iot-device-sdk-java-v2
48-
mvn install
58+
mvn clean install
4959
```
5060

5161
### Android
@@ -237,6 +247,80 @@ and receive.
237247
</pre>
238248
</details>
239249

250+
## fleet provisioning
251+
252+
This sample uses the AWS IoT
253+
[Fleet provisioning](https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html)
254+
to provision devices using either a CSR or KeysAndcertificate and subsequently calls RegisterThing.
255+
256+
On startup, the script subscribes to topics based on the request type of either CSR or Keys topics,
257+
publishes the request to corresponding topic and calls RegisterThing.
258+
259+
Source: `samples/Identity`
260+
261+
cd ~/samples/Identity
262+
263+
Run the sample using CreateKeysAndCertificate:
264+
265+
```
266+
mvn exec:java -Dexec.mainClass="identity.FleetProvisioningSample" -Dexec.args="--endpoint <endpoint> --rootca <root ca path>
267+
--cert <cert path> --key <private key path> --templateName <templatename> --templateParameters <templateParams>"
268+
```
269+
270+
Run the sample using CreateCertificateFromCsr:
271+
272+
```
273+
mvn exec:java -Dexec.mainClass="identity.FleetProvisioningSample" -Dexec.args="--endpoint <endpoint> --rootca <root ca path>
274+
--cert <cert path> --key <private key path> --templateName <templatename> --templateParameters <templateParams> --csr <csr path>"
275+
```
276+
277+
Your Thing's
278+
[Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html)
279+
must provide privileges for this sample to connect, subscribe, publish,
280+
and receive.
281+
282+
<details>
283+
<summary>(see sample policy)</summary>
284+
<pre>
285+
{
286+
"Version": "2012-10-17",
287+
"Statement": [
288+
{
289+
"Effect": "Allow",
290+
"Action": [
291+
"iot:Publish"
292+
],
293+
"Resource": [
294+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create/json",
295+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create-from-csr/json",
296+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/provisioning-templates/<b>templatename<b>/provision/json"
297+
]
298+
},
299+
{
300+
"Effect": "Allow",
301+
"Action": [
302+
"iot:Receive",
303+
"iot:Subscribe"
304+
],
305+
"Resource": [
306+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create/json/accepted",
307+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create/json/rejected",
308+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create-from-csr/json/accepted",
309+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/certificates/create-from-csr/json/rejected",
310+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/provisioning-templates/<b>templatename<b>/provision/json/accepted",
311+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/$aws/provisioning-templates/<b>templatename<b>/provision/json/rejected"
312+
]
313+
},
314+
{
315+
"Effect": "Allow",
316+
"Action": "iot:Connect",
317+
"Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/samples-client-id"
318+
}
319+
]
320+
}
321+
</pre>
322+
</details>
323+
240324
# License
241325

242326
This library is licensed under the Apache 2.0 License.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<module>samples/PubSubStress</module>
1414
<module>samples/RawPubSub</module>
1515
<module>samples/Shadow</module>
16-
<module>samples/Greengrass</module>
16+
<module>samples/Identity</module>
1717
</modules>
1818

1919
<build>

samples/Identity/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>software.amazon.awssdk.iotdevicesdk</groupId>
5+
<artifactId>Identity</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>${project.groupId}:${project.artifactId}</name>
9+
<description>Java bindings for the AWS IoT Core Service</description>
10+
<url>https://github.com/awslabs/aws-iot-device-sdk-java-v2</url>
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
<dependencies>
17+
<dependency>
18+
<groupId>software.amazon.awssdk.iotdevicesdk</groupId>
19+
<artifactId>aws-iot-device-sdk</artifactId>
20+
<version>1.0.0-SNAPSHOT</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>com.google.code.gson</groupId>
24+
<artifactId>gson</artifactId>
25+
<version>2.8.5</version>
26+
<scope>compile</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.fasterxml.jackson.core</groupId>
30+
<artifactId>jackson-core</artifactId>
31+
<version>2.10.3</version>
32+
</dependency>
33+
</dependencies>
34+
35+
<!-- include below build tag to your existing pom.xml -->
36+
<build>
37+
<plugins>
38+
<plugin>
39+
40+
<!-- Building an executable jar -->
41+
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-jar-plugin</artifactId>
44+
<version>3.1.0</version>
45+
<configuration>
46+
<archive>
47+
<manifest>
48+
49+
<!-- give full qualified name of your main class-->
50+
<mainClass>identity.FleetProvisioningSample</mainClass>
51+
52+
</manifest>
53+
</archive>
54+
</configuration>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
</project>

0 commit comments

Comments
 (0)