Skip to content

Commit 53dd4d6

Browse files
authored
Enhance Samples (#834)
* update command line parser * clean up mqtt5 x509 sample and readme * fix warning as error on windows * update pubsub sample and readme * add mqtt5 aws websocket * update CI * add pkcs11 sample * add custom auth signed ample * add unsigned custom auth * update sample script * wip update sample folder structure * update sample folder structure * wip: remove command utils * wip : update build samples * fix commandline * fix cmake for commands * fix typo * build sample for device_defender * fix uuid * fix compile error and sample cmake * remove command utils * fix shadow update * basic report * update error print for DDTestRun, remove ca_file * fix dd test run path & mqtt3 ci * add print to argument lists * fix script for new argument parasing * remove prints and adjust commands * remove job id * remove linux smoke test * update cr changes * add back mqtt3 service tests * remove jobid
1 parent db30688 commit 53dd4d6

File tree

75 files changed

+4274
-2855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4274
-2855
lines changed

.builder/actions/build_samples.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@ def run(self, env):
1919

2020
steps = []
2121
samples = [
22-
'samples/commands/commands-sandbox',
22+
'samples/service_clients/commands/commands-sandbox',
2323
'samples/greengrass/basic_discovery',
2424
'samples/greengrass/ipc',
25-
'samples/fleet_provisioning/provision-basic',
26-
'samples/fleet_provisioning/provision-csr',
27-
'samples/jobs/jobs-sandbox',
28-
'samples/mqtt5/mqtt5_pubsub',
29-
'samples/secure_tunneling/secure_tunnel',
30-
'samples/secure_tunneling/tunnel_notification',
31-
'samples/shadow/shadow-sandbox',
25+
'samples/service_clients/fleet_provisioning/provision-basic',
26+
'samples/service_clients/fleet_provisioning/provision-csr',
27+
'samples/service_clients/jobs/jobs-sandbox',
28+
'samples/mqtt/mqtt5_x509',
29+
'samples/mqtt/mqtt5_aws_websocket',
30+
'samples/mqtt/mqtt5_custom_auth_signed',
31+
'samples/mqtt/mqtt5_custom_auth_unsigned',
32+
'samples/mqtt/mqtt5_pkcs11',
33+
'samples/others/secure_tunneling/secure_tunnel',
34+
'samples/others/secure_tunneling/tunnel_notification',
35+
'samples/service_clients/shadow/shadow-sandbox',
3236
]
3337

3438
defender_samples = []
3539
# Linux only builds
3640
if sys.platform == "linux" or sys.platform == "linux2":
37-
defender_samples.append('samples/device_defender/basic_report')
38-
defender_samples.append('samples/device_defender/mqtt5_basic_report')
41+
defender_samples.append('samples/others/device_defender/mqtt5_basic_report')
3942

4043
servicetests = [
4144
'servicetests/tests/JobsExecution/',

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ jobs:
240240
run: |
241241
cd ${{ env.CI_FOLDER }}
242242
echo "Starting to run AppVerifier with mqtt5 pub-sub sample"
243-
python ${{ env.CI_UTILS_FOLDER }}/appverifier_launch_sample.py --sample_file ".\aws-iot-device-sdk-cpp-v2\build\samples\mqtt5\mqtt5_pubsub\RelWithDebInfo\mqtt5_pubsub.exe" --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/mqtt5/us/mqtt5_thing/cert' --sample_secret_private_key 'ci/mqtt5/us/mqtt5_thing/key'
243+
python ${{ env.CI_UTILS_FOLDER }}/appverifier_launch_sample.py --sample_file ".\aws-iot-device-sdk-cpp-v2\build\samples\mqtt\mqtt5_x509\RelWithDebInfo\mqtt5_x509.exe" --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/mqtt5/us/mqtt5_thing/cert' --sample_secret_private_key 'ci/mqtt5/us/mqtt5_thing/key'
244244
245245
windows-shared-lib:
246246
runs-on: windows-latest

codebuild/linux-integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ phases:
1515
commands:
1616
- echo Build started on `date`
1717
# Building of dependencies happens in setup-linux
18-
- $CODEBUILD_SRC_DIR/codebuild/samples/setup-linux.sh
18+
- $CODEBUILD_SRC_DIR/codebuild/setup-linux.sh
1919

2020
# Run the integration tests
2121
- $CODEBUILD_SRC_DIR/codebuild/integration-tests.sh

codebuild/samples/linux-smoke-tests.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.
File renamed without changes.

devicedefender/script/DDTestRun.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ def delete_thing_with_certi(thingName, certiId, certiArn):
4343
thing_arn = None
4444
client_made_thing = False
4545
client_made_policy = False
46-
use_mqtt5 = False
47-
if len(sys.argv) > 1:
48-
use_mqtt5 = (sys.argv[1] == "mqtt5")
49-
print("Run Device Defender with Mqtt5 Client")
5046

5147
##############################################
5248
# create a test thing
@@ -227,30 +223,21 @@ def delete_thing_with_certi(thingName, certiId, certiArn):
227223

228224
print("[Device Defender]Info: Running sample (this should take ~60 seconds).")
229225

230-
if use_mqtt5:
231-
# Run the sample:
232-
exe_path = "build/samples/device_defender/mqtt5_basic_report/"
233-
# If running locally, comment out the line above and uncomment the line below:
234-
#exe_path = "samples/device_defender/basic_report/build/"
226+
# Run the sample:
227+
exe_path = "build/samples/others/device_defender/mqtt5_basic_report/"
228+
# If running locally, comment out the line above and uncomment the line below:
229+
#exe_path = "samples/others/device_defender/mqtt5_basic_report/build/"
235230

236-
# Windows has a different build folder structure, but this ONLY runs on Linux currently so we do not need to worry about it
237-
exe_path = os.path.join(exe_path, "mqtt5-basic-report")
238-
else:
239-
# Run the sample:
240-
exe_path = "build/samples/device_defender/basic_report/"
241-
# If running locally, comment out the line above and uncomment the line below:
242-
#exe_path = "samples/device_defender/basic_report/build/"
243-
244-
# Windows has a different build folder structure, but this ONLY runs on Linux currently so we do not need to worry about it
245-
exe_path = os.path.join(exe_path, "basic-report")
231+
# Windows has a different build folder structure, but this ONLY runs on Linux currently so we do not need to worry about it
232+
exe_path = os.path.join(exe_path, "mqtt5-basic-report")
246233

247234
print("[Device Defender]Info: Start to run: " + exe_path)
248235
# The Device Defender sample will take ~1 minute to run even if successful
249236
# (since samples are sent every minute)
250237
arguments = [exe_path, "--endpoint", endpoint_response, "--cert",
251238
certificate_path, "--key", key_path, "--thing_name", thing_name, "--count", "2"]
252239
result = subprocess.run(arguments, timeout=60*2, check=True)
253-
print("[Device Defender]Info: Sample finished running.")
240+
print(f"[Device Defender]Info: Sample finished running, with result {result.returncode}")
254241

255242
# There does not appear to be any way to get the metrics from the device - so we'll assume that if it didn't return -1, then it worked
256243

@@ -272,7 +259,7 @@ def delete_thing_with_certi(thingName, certiId, certiArn):
272259
if client_made_policy:
273260
client.delete_policy(policyName=thing_name + "_policy")
274261

275-
print("[Device Defender]Error: Failed to test: Basic Report")
262+
print(f"[Device Defender]Error: Failed to test: Basic Report {e}")
276263
exit(-1)
277264

278265
print("[Device Defender]Info: Basic Report sample test passed")

documents/FAQ.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ If you are just getting started make sure you [install this sdk](https://github.
2020
### How do I enable logging?
2121

2222
``` c++
23-
ApiHandle apiHandle;
24-
apiHandle.InitializeLogging(Aws::Crt::LogLevel::Error, stderr);
23+
#include <aws/crt/Api.h>
24+
25+
Aws::Crt::ApiHandle apiHandle;
26+
apiHandle.InitializeLogging(Aws::Crt::LogLevel::Debug, stderr);
2527
```
28+
29+
**LogLevel**: LogLevel has the following options: `Trace`, `Debug`, `Info`, `Warn`, `Error`, `Fatal`, or `None`. Defaults to `Warn`.
30+
2631
You can also enable [CloudWatch logging](https://docs.aws.amazon.com/iot/latest/developerguide/cloud-watch-logs.html) for IoT which will provide you with additional information that is not available on the client side sdk.
2732

2833
### I keep getting AWS_ERROR_MQTT_UNEXPECTED_HANGUP
@@ -99,7 +104,6 @@ Here is an example launch.json file to run the pubsub sample
99104
"program": "${workspaceFolder}/samples/pub_sub/basic_pub_sub/build/basic-pub-sub",
100105
"args": [
101106
"--endpoint", "<account-number>-ats.iot.<region>.amazonaws.com",
102-
"--ca_file", "<path to root-CA>",
103107
"--cert", "<path to cert>",
104108
"--key", "<path to key>",
105109
"--client-id", "test-client"
@@ -116,7 +120,6 @@ Here is an example launch.json file to run the pubsub sample
116120
* Root CA Certificates
117121
* Download the root CA certificate file that corresponds to the type of data endpoint and cipher suite you're using (You most likely want Amazon Root CA 1)
118122
* Generated and provided by Amazon. You can download it [here](https://www.amazontrust.com/repository/) or download it when getting the other certificates from the AWS console
119-
* When using samples it can look like this: `--ca_file root-CA.crt`
120123
* Device certificate
121124
* Intermediate device certificate that is used to generate the key below
122125
* When using samples it can look like this: `--cert abcde12345-certificate.pem.crt`

documents/MIGRATION_GUIDE.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,8 @@ samples.
13691369
13701370
It's always helpful to look at a working example to see how new functionality works,
13711371
to be able to tweak different options, to compare with existing code.
1372-
For that reason, we implemented a [Publish/Subscribe example](https://github.com/aws/aws-iot-device-sdk-cpp-v2/tree/main/samples/mqtt5/mqtt5_pubsub)
1373-
([source code](https://github.com/aws/aws-iot-device-sdk-cpp-v2/blob/main/samples/mqtt5/mqtt5_pubsub/main.cpp))
1372+
For that reason, we implemented a [X509 Publish/Subscribe example](https://github.com/aws/aws-iot-device-sdk-cpp-v2/tree/main/samples/mqtt/mqtt5_x509)
1373+
([source code](https://github.com/aws/aws-iot-device-sdk-cpp-v2/blob/main/samples/mqtt/mqtt5_x509/main.cpp))
13741374
in the v2 SDK similar to a sample provided by the v1 SDK (see a corresponding
13751375
[readme section](https://github.com/aws/aws-iot-device-sdk-cpp/blob/master/samples/README.md) and
13761376
[source code](https://github.com/aws/aws-iot-device-sdk-cpp/blob/master/samples/PubSub/PubSub.cpp)).
@@ -1438,9 +1438,7 @@ method in PublishPacketBuilder class.
14381438
14391439
**Shared Subscriptions**\
14401440
Shared Subscriptions allow multiple clients to share a subscription to a topic and only one client
1441-
will receive messages published to that topic using a random distribution.\
1442-
For more information, see a [shared subscription sample](https://github.com/aws/aws-iot-device-sdk-cpp-v2/blob/main/samples/mqtt5/mqtt5_shared_subscription/README.md)
1443-
in the v2 SDK.
1441+
will receive messages published to that topic using a random distribution.
14441442
14451443
> [!NOTE]
14461444
> AWS Iot Core supports Shared Subscriptions for both MQTT3 and MQTT5. For more information, see

documents/Secure_Tunnel_Userguide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ secureTunnel->SendMessage(message);
249249

250250
# Secure Tunnel Best Practices
251251
* You MUST NOT perform blocking operations on any callback, or you will cause a deadlock.
252-
* If you do not provide a Client Token during creation of the Secure Tunnel, one will be automatically generated for you to use in reconnections. This token is not saved outside of the current Secure Tunnel Client. If the Client is destroyed, the original access tokens must be rotated to connect to the secure tunnel again. Information on rotating tokens can be found here: https://docs.aws.amazon.com/iot/latest/developerguide/iot-secure-tunneling-troubleshooting.html
252+
* If you do not provide a Client Token during creation of the Secure Tunnel, one will be automatically generated for you to use in reconnection. This token is not saved outside of the current Secure Tunnel Client. If the Client is destroyed, the original access tokens must be rotated to connect to the secure tunnel again. Information on rotating tokens can be found here: https://docs.aws.amazon.com/iot/latest/developerguide/iot-secure-tunneling-troubleshooting.html
253253
* Client tokens MUST be unique. You cannot for example, pair a Client Token with an Access Token on one secure tunnel, and then use the same Client Token with a different Access Token on a separate secure tunnel. The Secure Tunnel Service will not allow a Client Token to be paired with more than one Access Token.
254254
* A Secure Tunnel Client that has called `Start()` will continue to attempt to connect the Secure Tunnel Service until `Stop()` is called, even if the Secure Tunnel it is trying to connect with has been closed. You MUST call `Stop()` to cease future connection attempts.
255-
* The [onStreamStarted](#onstreamstarted) and [onConnectionStarted](#onconnectionstarted) callbacks should be set to detect and store the service id and/or connection id of streams started by a source device for use with messages. The [Secure Tunnel sample](../samples/secure_tunneling/secure_tunnel/README.md) provides an basic example of how this can be done.
255+
* The [onStreamStarted](#onstreamstarted) and [onConnectionStarted](#onconnectionstarted) callbacks should be set to detect and store the service id and/or connection id of streams started by a source device for use with messages. The [Secure Tunnel sample](../samples/others/secure_tunneling/secure_tunnel/README.md) provides an basic example of how this can be done.
256256
* Outgoing messages MUST be assigned a service id and/or a connection id if the established stream contains a service id or a connection id or the message will be rejected. e.g. If a stream is started using service id "ssh" and connection id (1), a message sent in response must also include the service id "ssh" and connection id (1) or it will not find an active stream to send it on. Refer to the [Send Message](#send-message) code block for instruction on adding a service id and/or connection id to your message.
257257

samples/CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ cmake_minimum_required(VERSION 3.9...3.31)
22

33
project(aws-iot-device-sdk-cpp-v2-samples)
44

5-
add_subdirectory(device_defender/basic_report)
6-
add_subdirectory(device_defender/mqtt5_basic_report)
7-
add_subdirectory(fleet_provisioning/provision-basic)
8-
add_subdirectory(fleet_provisioning/provision-csr)
5+
add_subdirectory(others/device_defender/mqtt5_basic_report)
6+
add_subdirectory(service_clients/fleet_provisioning/provision-basic)
7+
add_subdirectory(service_clients/fleet_provisioning/provision-csr)
98
add_subdirectory(greengrass/ipc)
109
add_subdirectory(greengrass/basic_discovery)
11-
add_subdirectory(jobs/jobs-sandbox)
12-
add_subdirectory(mqtt5/mqtt5_pubsub)
13-
add_subdirectory(secure_tunneling/secure_tunnel)
14-
add_subdirectory(secure_tunneling/tunnel_notification)
15-
add_subdirectory(shadow/shadow_sync)
16-
add_subdirectory(commands/commands-sandbox)
10+
add_subdirectory(service_clients/jobs/jobs-sandbox)
11+
add_subdirectory(mqtt/mqtt5_x509)
12+
add_subdirectory(mqtt/mqtt5_aws_websocket)
13+
add_subdirectory(mqtt/mqtt5_custom_auth_signed)
14+
add_subdirectory(mqtt/mqtt5_custom_auth_unsigned)
15+
add_subdirectory(mqtt/mqtt5_pkcs11)
16+
add_subdirectory(others/secure_tunneling/secure_tunnel)
17+
add_subdirectory(others/secure_tunneling/tunnel_notification)
18+
add_subdirectory(service_clients/shadow/shadow-sandbox)
19+
add_subdirectory(service_clients/commands/commands-sandbox)

0 commit comments

Comments
 (0)