Skip to content

Commit 6e653e6

Browse files
authored
All V2 SDK samples can share policies. (#128)
ISSUE: Currently, the "Getting Started Kit" vended by the IoT console vends a policy that doesn't match the strings used by any V2 SDK samples. So they fail right off the bat 😢 SOLUTION: Let's get all the V2 SDKs using the same strings, then we can create a policy to fit them all. I'd like to put wildcards in the new policy so users can toy around a little bit, but include the word "test" everywhere so they feel inclined to change it before they ship. Also, let's get all the samples putting randomness into the client-id, since colliding IDs are a frequent source of confusion. Also, make a default topic for pubsub samples
1 parent 8daf749 commit 6e653e6

8 files changed

Lines changed: 97 additions & 80 deletions

File tree

README.md

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# AWS IoT SDK for C++ v2
2+
23
This document provides information about the AWS IoT device SDK for C++ V2.
34

45
If you have any issues or feature requests, please file an issue or pull request.
@@ -14,27 +15,27 @@ This SDK is built on the AWS Common Runtime, a collection of libraries
1415
cross-platform, high-performance, secure, and reliable. The libraries are bound
1516
to C++ by the [aws-crt-cpp](https://github.com/awslabs/aws-crt-cpp) package.
1617

17-
1818
*__Jump To:__*
19+
1920
* [Installation](#Installation)
2021
* [Samples](samples)
2122
* [Getting Help](#Getting-Help)
2223
* [Giving Feedback and Contributions](#Giving-Feedback-and-Contributions)
2324
* [More Resources](#More-Resources)
2425

25-
26-
2726
## Installation
2827

2928
### Minimum Requirements
30-
* C++ 11 or higher
31-
* CMake 3.1+
32-
* Clang 3.9+ or GCC 4.4+ or MSVC 2015+
3329

30+
* C++ 11 or higher
31+
* CMake 3.1+
32+
* Clang 3.9+ or GCC 4.4+ or MSVC 2015+
3433

3534
### Build from source
35+
3636
#### Automatically Build and Install AWS Dependencies
37-
```sh
37+
38+
``` sh
3839
mkdir sdk-cpp-workspace
3940
cd sdk-cpp-workspace
4041
git clone --recursive https://github.com/aws/aws-iot-device-sdk-cpp-v2.git
@@ -43,9 +44,10 @@ cd aws-iot-device-sdk-cpp-v2-build
4344
cmake -DCMAKE_INSTALL_PREFIX="<absolute path sdk-cpp-workspace dir>" -DBUILD_DEPS=ON ../aws-iot-device-sdk-cpp-v2
4445
cmake --build . --target install
4546
```
47+
4648
#### Using a Pre-Built aws-crt-cpp (Most useful for development of this package)
4749

48-
```sh
50+
``` sh
4951
mkdir aws-iot-device-sdk-cpp-v2-build
5052
cd aws-iot-device-sdk-cpp-v2-build
5153
cmake -DCMAKE_INSTALL_PREFIX="<absolute path sdk-cpp-workspace dir>" -DCMAKE_PREFIX_PATH="<absolute path sdk-cpp-workspace dir>" -DBUILD_DEPS=OFF ../aws-iot-device-sdk-cpp-v2
@@ -56,51 +58,43 @@ cmake --build . --target install
5658

5759
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.7.3, when a stored private key from the Keychain is used, the following will be logged at the "info" log level:
5860

59-
```
61+
```
6062
static: certificate has an existing certificate-key pair that was previously imported into the Keychain. Using key from Keychain instead of the one provided.
6163
```
6264

6365
## Samples
6466

6567
[Samples README](samples)
6668

67-
68-
6969
## Getting Help
7070

7171
Use the following sources for information :
7272

73-
* Check api and developer guides.
74-
* Check for similar issues already opened.
73+
* Check api and developer guides.
74+
* Check for similar issues already opened.
7575

7676
If you still can’t find a solution to your problem open an [issue](https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues)
7777

78-
79-
8078
## Giving Feedback and Contributions
8179

8280
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.
8381

84-
* [Contributions Guidelines](CONTRIBUTING.md)
85-
* Articulate your feature request or upvote existing ones on our [Issues](https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues?q=is%3Aissue+is%3Aopen+label%3Afeature-request) page.
86-
* Submit [Issues](https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues)
87-
88-
82+
* [Contributions Guidelines](CONTRIBUTING.md)
83+
* Articulate your feature request or upvote existing ones on our [Issues](https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues?q=is%3Aissue+is%3Aopen+label%3Afeature-request) page.
84+
* Submit [Issues](https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues)
8985

9086
## More Resources
9187

92-
* [AWS IoT Core Documentation](https://docs.aws.amazon.com/iot/)
93-
* [Developer Guide](https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html) ([source](https://github.com/awsdocs/aws-iot-docs))
94-
* [Issues](https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues)
95-
* [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)
88+
* [AWS IoT Core Documentation](https://docs.aws.amazon.com/iot/)
89+
* [Developer Guide](https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html) ([source](https://github.com/awsdocs/aws-iot-docs))
90+
* [Issues](https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues)
91+
* [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)
9692

9793
Integration with AWS IoT Services such as
9894
[Device Shadow](https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html)
9995
and [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html)
10096
is provided by code that been generated from a model of the service.
10197

102-
103-
10498
## License
10599

106-
This library is licensed under the [Apache 2.0 License](LICENSE).
100+
This library is licensed under the [Apache 2.0 License](LICENSE).

samples/README.md

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,48 @@ and receive.
2222
<summary>(see sample policy)</summary>
2323
<pre>
2424
{
25-
"Effect": "Allow",
26-
"Action": [
27-
"iot:Receive",
28-
"iot:Publish"
29-
],
30-
"Resource": [
31-
"arn:aws:iot:<your-region>:<your-id>:topic/a/b"
32-
],
33-
},
34-
{
35-
"Effect": "Allow",
36-
"Action": [
25+
"Version": "2012-10-17",
26+
"Statement": [
27+
28+
{
29+
"Effect": "Allow",
30+
"Action": [
31+
"iot:Publish",
32+
"iot:Receive"
33+
],
34+
"Resource": [
35+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/test/topic"
36+
]
37+
},
38+
{
39+
"Effect": "Allow",
40+
"Action": [
3741
"iot:Subscribe"
38-
],
39-
"Resource": [
40-
"arn:aws:iot:<your-region>:<your-id>:topicfilter/a/b"
41-
]
42+
],
43+
"Resource": [
44+
"arn:aws:iot:<b>region</b>:<b>account</b>:topicfilter/test/topic"
45+
]
46+
},
47+
{
48+
"Effect": "Allow",
49+
"Action": [
50+
"iot:Connect"
51+
],
52+
"Resource": [
53+
"arn:aws:iot:<b>region</b>:<b>account</b>:client/test-*"
54+
]
55+
}
56+
57+
]
4258
}
4359
</pre>
4460
</details>
4561

4662
To run the basic MQTT Pub-Sub use the following command:
4763

48-
```sh
49-
./basic-pub-sub --endpoint <endpoint> --ca_file <path to root CA>
50-
--cert <path to the certificate> --key <path to the private key>
64+
``` sh
65+
./basic-pub-sub --endpoint <endpoint> --ca_file <path to root CA>
66+
--cert <path to the certificate> --key <path to the private key>
5167
--topic <topic name>
5268
```
5369

@@ -59,7 +75,6 @@ This is a starting point for using custom
5975

6076
source: `samples/mqtt/raw_pub_sub`
6177

62-
6378
## Fleet provisioning
6479

6580
This sample uses the AWS IoT
@@ -70,22 +85,21 @@ On startup, the script subscribes to topics based on the request type of either
7085
publishes the request to corresponding topic and calls RegisterThing.
7186

7287
Source: `samples/identity/fleet_provisioning`
73-
7488
cd ~/aws-iot-device-sdk-cpp-v2-build/samples/identity/fleet_provisioning
7589

7690
Run the sample like this to provision using CreateKeysAndCertificate:
77-
78-
```sh
79-
./fleet-provisioning --endpoint <endpoint> --ca_file <path to root CA>
80-
--cert <path to the certificate> --key <path to the private key>
91+
92+
``` sh
93+
./fleet-provisioning --endpoint <endpoint> --ca_file <path to root CA>
94+
--cert <path to the certificate> --key <path to the private key>
8195
--template_name <template name> --template_parameters <template parameters json>
8296
```
8397

8498
Run the sample like this to provision using Csr:
85-
86-
```sh
87-
./fleet-provisioning --endpoint <endpoint> --ca_file <path to root CA>
88-
--cert <path to the certificate> --key <path to the private key>
99+
100+
``` sh
101+
./fleet-provisioning --endpoint <endpoint> --ca_file <path to root CA>
102+
--cert <path to the certificate> --key <path to the private key>
89103
--template_name <template name> --template_parameters <template parameters json> --csr <path to the CSR in PEM format>
90104
```
91105

@@ -129,14 +143,13 @@ and receive.
129143
{
130144
"Effect": "Allow",
131145
"Action": "iot:Connect",
132-
"Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/samples-client-id"
146+
"Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/test-*"
133147
}
134148
]
135149
}
136150
</pre>
137151
</details>
138152

139-
140153
## Shadow
141154

142155
This sample uses the AWS IoT
@@ -170,6 +183,7 @@ and receive.
170183
{
171184
"Version": "2012-10-17",
172185
"Statement": [
186+
173187
{
174188
"Effect": "Allow",
175189
"Action": [
@@ -209,8 +223,9 @@ and receive.
209223
{
210224
"Effect": "Allow",
211225
"Action": "iot:Connect",
212-
"Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/samples-client-id"
226+
"Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/test-*"
213227
}
228+
214229
]
215230
}
216231
</pre>
@@ -239,6 +254,7 @@ and receive.
239254
{
240255
"Version": "2012-10-17",
241256
"Statement": [
257+
242258
{
243259
"Effect": "Allow",
244260
"Action": [
@@ -278,8 +294,9 @@ and receive.
278294
{
279295
"Effect": "Allow",
280296
"Action": "iot:Connect",
281-
"Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/samples-client-id"
297+
"Resource": "arn:aws:iot:<b>region</b>:<b>account</b>:client/test-*"
282298
}
299+
283300
]
284301
}
285302
</pre>

samples/greengrass/basic_discovery/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void s_printHelp()
3333
fprintf(stdout, "ca_file: ca file to use in verifying TLS connections.\n");
3434
fprintf(stdout, "\tIt's the path to a CA file in PEM format\n");
3535
fprintf(stdout, "thing_name: the name of your IOT thing\n");
36-
fprintf(stdout, "topic: targeted topic. Default is sdk/test/cpp-v2\n");
36+
fprintf(stdout, "topic: targeted topic. Default is test/topic\n");
3737
fprintf(stdout, "mode: default both\n");
3838
fprintf(stdout, "message: message to publish. default 'Hello World'\n");
3939
fprintf(stdout, "proxy-host: proxy host to use for discovery call. Default is to not use a proxy.\n");
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
7070
String keyPath;
7171
String caFile;
7272
String thingName;
73-
String topic("sdk/test/cpp-v2");
73+
String topic("test/topic");
7474
String mode("both");
7575
String message("Hello World");
7676

samples/identity/fleet_provisioning/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
9999
String certificatePath;
100100
String keyPath;
101101
String caFile;
102-
String clientId(Aws::Crt::UUID().ToString());
102+
String clientId(String("test-") + Aws::Crt::UUID().ToString());
103103
String templateName;
104104
String templateParameters;
105105
String csrFile;
@@ -242,7 +242,7 @@ int main(int argc, char *argv[])
242242
* Actually perform the connect dance.
243243
*/
244244
fprintf(stdout, "Connecting...\n");
245-
if (!connection->Connect("client_id12335456", true, 0))
245+
if (!connection->Connect(clientId.c_str(), true, 0))
246246
{
247247
fprintf(stderr, "MQTT Connection failed with error %s\n", ErrorDebugString(connection->LastError()));
248248
exit(-1);

samples/jobs/describe_job_execution/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ int main(int argc, char *argv[])
6969
String certificatePath;
7070
String keyPath;
7171
String caFile;
72+
String clientId(String("test-") + Aws::Crt::UUID().ToString());
7273
String thingName;
7374
String jobId;
7475

@@ -200,7 +201,7 @@ int main(int argc, char *argv[])
200201
* Actually perform the connect dance.
201202
*/
202203
fprintf(stdout, "Connecting...\n");
203-
if (!connection->Connect("client_id12335456", true, 0))
204+
if (!connection->Connect(clientId.c_str(), true, 0))
204205
{
205206
fprintf(stderr, "MQTT Connection failed with error %s\n", ErrorDebugString(connection->LastError()));
206207
exit(-1);

samples/mqtt/basic_pub_sub/main.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void s_printHelp()
2323
fprintf(
2424
stdout,
2525
"basic-pub-sub --endpoint <endpoint> --cert <path to cert>"
26-
" --key <path to key> --topic --ca_file <optional: path to custom ca>"
26+
" --key <path to key> --topic <topic> --ca_file <optional: path to custom ca>"
2727
" --use_websocket --signing_region <region> --proxy_host <host> --proxy_port <port>"
2828
" --x509 --x509_role_alias <role_alias> --x509_endpoint <endpoint> --x509_thing <thing_name>"
2929
" --x509_cert <path to cert> --x509_key <path to key> --x509_rootca <path to root ca>\n\n");
@@ -32,7 +32,7 @@ static void s_printHelp()
3232
stdout,
3333
"cert: path to your client certificate in PEM format. If this is not set you must specify use_websocket\n");
3434
fprintf(stdout, "key: path to your key in PEM format. If this is not set you must specify use_websocket\n");
35-
fprintf(stdout, "topic: topic to publish, subscribe to.\n");
35+
fprintf(stdout, "topic: topic to publish, subscribe to. (optional)\n");
3636
fprintf(stdout, "client_id: client id to use (optional)\n");
3737
fprintf(
3838
stdout,
@@ -91,8 +91,8 @@ int main(int argc, char *argv[])
9191
String certificatePath;
9292
String keyPath;
9393
String caFile;
94-
String topic;
95-
String clientId(Aws::Crt::UUID().ToString());
94+
String topic("test/topic");
95+
String clientId(String("test-") + Aws::Crt::UUID().ToString());
9696
String signingRegion;
9797
String proxyHost;
9898
uint16_t proxyPort(8080);
@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
108108
bool useX509 = false;
109109

110110
/*********************** Parse Arguments ***************************/
111-
if (!(s_cmdOptionExists(argv, argv + argc, "--endpoint") && s_cmdOptionExists(argv, argv + argc, "--topic")))
111+
if (!s_cmdOptionExists(argv, argv + argc, "--endpoint"))
112112
{
113113
s_printHelp();
114114
return 1;
@@ -132,8 +132,10 @@ int main(int argc, char *argv[])
132132
s_printHelp();
133133
return 1;
134134
}
135-
136-
topic = s_getCmdOption(argv, argv + argc, "--topic");
135+
if (s_getCmdOption(argv, argv + argc, "--topic"))
136+
{
137+
topic = s_getCmdOption(argv, argv + argc, "--topic");
138+
}
137139
if (s_cmdOptionExists(argv, argv + argc, "--ca_file"))
138140
{
139141
caFile = s_getCmdOption(argv, argv + argc, "--ca_file");

0 commit comments

Comments
 (0)