diff --git a/.builder/actions/build_samples.py b/.builder/actions/build_samples.py index 71b7c952f..90045b3fe 100644 --- a/.builder/actions/build_samples.py +++ b/.builder/actions/build_samples.py @@ -19,12 +19,17 @@ def run(self, env): steps = [] samples = [ + 'samples/deprecated/fleet_provisioning/fleet_provisioning', + 'samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning', + 'samples/deprecated/jobs/job_execution', + 'samples/deprecated/jobs/mqtt5_job_execution', + 'samples/deprecated/shadow/shadow_sync', + 'samples/deprecated/shadow/mqtt5_shadow_sync', 'samples/greengrass/basic_discovery', 'samples/greengrass/ipc', - 'samples/fleet_provisioning/fleet_provisioning', - 'samples/fleet_provisioning/mqtt5_fleet_provisioning', - 'samples/jobs/job_execution', - 'samples/jobs/mqtt5_job_execution', + 'samples/fleet_provisioning/provision-basic', + 'samples/fleet_provisioning/provision-csr', + 'samples/jobs/jobs-sandbox', 'samples/mqtt/basic_connect', 'samples/mqtt/custom_authorizer_connect', 'samples/mqtt/pkcs11_connect', @@ -40,8 +45,7 @@ def run(self, env): "samples/pub_sub/cycle_pub_sub", 'samples/secure_tunneling/secure_tunnel', 'samples/secure_tunneling/tunnel_notification', - 'samples/shadow/shadow_sync', - 'samples/shadow/mqtt5_shadow_sync', + 'samples/shadow/shadow-sandbox', ] defender_samples = [] diff --git a/.github/workflows/ci_run_fleet_provisioning_cfg.json b/.github/workflows/ci_run_fleet_provisioning_cfg.json index d795a6d6a..b4c0e51f3 100644 --- a/.github/workflows/ci_run_fleet_provisioning_cfg.json +++ b/.github/workflows/ci_run_fleet_provisioning_cfg.json @@ -1,6 +1,6 @@ { "language": "CPP", - "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/fleet_provisioning/fleet_provisioning/fleet-provisioning", + "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/deprecated/fleet_provisioning/fleet_provisioning/fleet-provisioning", "sample_region": "us-east-1", "sample_main_class": "", "arguments": [ diff --git a/.github/workflows/ci_run_fleet_provisioning_mqtt5_cfg.json b/.github/workflows/ci_run_fleet_provisioning_mqtt5_cfg.json index bc4408d3a..b569e1ee3 100644 --- a/.github/workflows/ci_run_fleet_provisioning_mqtt5_cfg.json +++ b/.github/workflows/ci_run_fleet_provisioning_mqtt5_cfg.json @@ -1,6 +1,6 @@ { "language": "CPP", - "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/fleet_provisioning/mqtt5_fleet_provisioning/mqtt5-fleet-provisioning", + "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/mqtt5-fleet-provisioning", "sample_region": "us-east-1", "sample_main_class": "", "arguments": [ diff --git a/.github/workflows/ci_run_jobs_cfg.json b/.github/workflows/ci_run_jobs_cfg.json index 82a6ebac7..e9ad04a00 100644 --- a/.github/workflows/ci_run_jobs_cfg.json +++ b/.github/workflows/ci_run_jobs_cfg.json @@ -1,6 +1,6 @@ { "language": "CPP", - "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/jobs/job_execution/job-execution", + "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/deprecated/jobs/job_execution/job-execution", "sample_region": "us-east-1", "sample_main_class": "", "arguments": [ diff --git a/.github/workflows/ci_run_jobs_mqtt5_cfg.json b/.github/workflows/ci_run_jobs_mqtt5_cfg.json index 91eeb6428..c8907ae2e 100644 --- a/.github/workflows/ci_run_jobs_mqtt5_cfg.json +++ b/.github/workflows/ci_run_jobs_mqtt5_cfg.json @@ -1,6 +1,6 @@ { "language": "CPP", - "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/jobs/mqtt5_job_execution/mqtt5-job-execution", + "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/deprecated/jobs/mqtt5_job_execution/mqtt5-job-execution", "sample_region": "us-east-1", "sample_main_class": "", "arguments": [ diff --git a/.github/workflows/ci_run_shadow_cfg.json b/.github/workflows/ci_run_shadow_cfg.json index c3426cacd..8166e7151 100644 --- a/.github/workflows/ci_run_shadow_cfg.json +++ b/.github/workflows/ci_run_shadow_cfg.json @@ -1,6 +1,6 @@ { "language": "CPP", - "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/shadow/shadow_sync/shadow-sync", + "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/deprecated/shadow/shadow_sync/shadow-sync", "sample_region": "us-east-1", "sample_main_class": "", "arguments": [ diff --git a/.github/workflows/ci_run_shadow_mqtt5_cfg.json b/.github/workflows/ci_run_shadow_mqtt5_cfg.json index 8f173b5e1..5713df596 100644 --- a/.github/workflows/ci_run_shadow_mqtt5_cfg.json +++ b/.github/workflows/ci_run_shadow_mqtt5_cfg.json @@ -1,6 +1,6 @@ { "language": "CPP", - "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/shadow/mqtt5_shadow_sync/mqtt5-shadow-sync", + "sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/deprecated/shadow/mqtt5_shadow_sync/mqtt5-shadow-sync", "sample_region": "us-east-1", "sample_main_class": "", "arguments": [ diff --git a/codebuild/samples/shadow-linux.sh b/codebuild/samples/shadow-linux.sh index a04b05f1c..9956b0062 100755 --- a/codebuild/samples/shadow-linux.sh +++ b/codebuild/samples/shadow-linux.sh @@ -4,7 +4,8 @@ set -e env -pushd $CODEBUILD_SRC_DIR/samples/shadow/shadow_sync +# v1 MQTT311 shadow sample +pushd $CODEBUILD_SRC_DIR/samples/deprecated/shadow/shadow_sync mkdir _build cd _build @@ -17,3 +18,29 @@ echo "Shadow-Sync test" ./shadow-sync --endpoint $ENDPOINT --key /tmp/privatekey.pem --cert /tmp/certificate.pem --thing_name CI_CodeBuild_Thing --is_ci true popd + +# v1 MQTT5 shadow sample +pushd $CODEBUILD_SRC_DIR/samples/deprecated/shadow/mqtt5_shadow_sync + +mkdir _build +cd _build +cmake -DCMAKE_PREFIX_PATH=/tmp/install .. +make -j + +ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "ci/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') + +echo "Shadow-Sync test" +./mqtt5-shadow-sync --endpoint $ENDPOINT --key /tmp/privatekey.pem --cert /tmp/certificate.pem --thing_name CI_CodeBuild_Thing --is_ci true + +popd + +# v2 MQTT5 shadow sample - smaple is interactive so build but don't run + +pushd $CODEBUILD_SRC_DIR/samples/shadow/shadow-sandbox + +mkdir _build +cd _build +cmake -DCMAKE_PREFIX_PATH=/tmp/install .. +make -j + +popd \ No newline at end of file diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 2d9193231..bb5c519c1 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -4,12 +4,11 @@ project(aws-iot-device-sdk-cpp-v2-samples) add_subdirectory(device_defender/basic_report) add_subdirectory(device_defender/mqtt5_basic_report) +add_subdirectory(fleet_provisioning/provision-basic) +add_subdirectory(fleet_provisioning/provision-csr) add_subdirectory(greengrass/ipc) add_subdirectory(greengrass/basic_discovery) -add_subdirectory(fleet_provisioning/fleet_provisioning) -add_subdirectory(fleet_provisioning/mqtt5_fleet_provisioning) -add_subdirectory(jobs/job_execution) -add_subdirectory(jobs/mqtt5_job_execution) +add_subdirectory(jobs/jobs-sandbox) add_subdirectory(mqtt/basic_connect) add_subdirectory(mqtt/custom_authorizer_connect) add_subdirectory(mqtt/pkcs11_connect) @@ -25,4 +24,11 @@ add_subdirectory(pub_sub/cycle_pub_sub) add_subdirectory(secure_tunneling/secure_tunnel) add_subdirectory(secure_tunneling/tunnel_notification) add_subdirectory(shadow/shadow_sync) -add_subdirectory(shadow/mqtt5_shadow_sync) + + +add_subdirectory(deprecated/shadow/shadow_sync) +add_subdirectory(deprecated/shadow/mqtt5_shadow_sync) +add_subdirectory(deprecated/fleet_provisioning/fleet_provisioning) +add_subdirectory(deprecated/fleet_provisioning/mqtt5_fleet_provisioning) +add_subdirectory(deprecated/jobs/job_execution) +add_subdirectory(deprecated/jobs/mqtt5_job_execution) diff --git a/samples/README.md b/samples/README.md index cc90592e0..6e75f7deb 100644 --- a/samples/README.md +++ b/samples/README.md @@ -9,9 +9,6 @@ + [MQTT over Websockets with Cognito](./mqtt5/mqtt5_pubsub/README.md#mqtt-over-websockets-with-cognito) + [HTTP Proxy](./mqtt5/mqtt5_pubsub/README.md#http-proxy) * [Mqtt5 Shared Subscription](./mqtt5/mqtt5_shared_subscription/README.md) -* [Mqtt5 Jobs](./jobs/mqtt5_job_execution/README.md) -* [Mqtt5 Shadow](./shadow/mqtt5_shadow_sync/README.md) -* [Mqtt5 Fleet Provisioning](./fleet_provisioning/mqtt5_fleet_provisioning/README.md) ## MQTT311 Samples * [Basic Pub-Sub](./pub_sub/basic_pub_sub/README.md) * [Basic Connect](./mqtt/basic_connect/README.md) @@ -22,10 +19,11 @@ * [Windows Certificate MQTT Connect](./mqtt/windows_cert_connect/README.md) * [Custom Authorizer Connect](./mqtt/custom_authorizer_connect/README.md) * [Cognito Connect](./mqtt/cognito_connect/README.md) -* [Shadow](./shadow/shadow_sync/README.md) -* [Jobs](./jobs/job_execution/README.md) -* [Fleet provisioning](./fleet_provisioning/fleet_provisioning/README.md) ## Other Samples +* [Jobs Sandbox](./jobs/jobs-sandbox/README.md) +* [Shadow Sandbox](./shadow/shadow-sandbox/README.md) +* [Basic Fleet Provisioning](./fleet_provisioning/provision-basic/README.md) +* [CSR Fleet Provisioning](./fleet_provisioning/provision-csr/README.md) * [Secure Tunnel](./secure_tunneling/secure_tunnel/README.md) * [Secure Tunnel Notification](./secure_tunneling/tunnel_notification/README.md) * [Cycle Pub-Sub](./pub_sub/cycle_pub_sub/README.md) diff --git a/samples/deprecated/fleet_provisioning/fleet_provisioning/CMakeLists.txt b/samples/deprecated/fleet_provisioning/fleet_provisioning/CMakeLists.txt new file mode 100644 index 000000000..8105d7a43 --- /dev/null +++ b/samples/deprecated/fleet_provisioning/fleet_provisioning/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.9) +# note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12 +project(fleet-provisioning CXX) + +file(GLOB SRC_FILES + "*.cpp" + "../../../utils/CommandLineUtils.cpp" + "../../../utils/CommandLineUtils.h" +) + +add_executable(${PROJECT_NAME} ${SRC_FILES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 14) + +#set warnings +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +else () + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror) +endif () + +find_package(aws-crt-cpp REQUIRED) +find_package(IotIdentity-cpp REQUIRED) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) + +target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-crt-cpp AWS::IotIdentity-cpp) diff --git a/samples/fleet_provisioning/fleet_provisioning/README.md b/samples/deprecated/fleet_provisioning/fleet_provisioning/README.md similarity index 99% rename from samples/fleet_provisioning/fleet_provisioning/README.md rename to samples/deprecated/fleet_provisioning/fleet_provisioning/README.md index d631083f7..4226783c8 100644 --- a/samples/fleet_provisioning/fleet_provisioning/README.md +++ b/samples/deprecated/fleet_provisioning/fleet_provisioning/README.md @@ -1,6 +1,6 @@ # Fleet provisioning -[**Return to main sample list**](../../README.md) +[**Return to main sample list**](../../../README.md) This sample uses the AWS IoT [Fleet provisioning](https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html) to provision devices using either a CSR or Keys-And-Certificate and subsequently calls RegisterThing. This allows you to create new AWS IoT Core things using a Fleet Provisioning Template. diff --git a/samples/fleet_provisioning/fleet_provisioning/main.cpp b/samples/deprecated/fleet_provisioning/fleet_provisioning/main.cpp similarity index 99% rename from samples/fleet_provisioning/fleet_provisioning/main.cpp rename to samples/deprecated/fleet_provisioning/fleet_provisioning/main.cpp index cc1f5bcaf..a4d6692d5 100644 --- a/samples/fleet_provisioning/fleet_provisioning/main.cpp +++ b/samples/deprecated/fleet_provisioning/fleet_provisioning/main.cpp @@ -29,7 +29,7 @@ #include -#include "../../utils/CommandLineUtils.h" +#include "../../../utils/CommandLineUtils.h" using namespace Aws::Crt; using namespace Aws::Iotidentity; diff --git a/samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/CMakeLists.txt b/samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/CMakeLists.txt new file mode 100644 index 000000000..81fcaaa0a --- /dev/null +++ b/samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.9) +# note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12 +project(mqtt5-fleet-provisioning CXX) + +file(GLOB SRC_FILES + "*.cpp" + "../../../utils/CommandLineUtils.cpp" + "../../../utils/CommandLineUtils.h" +) + +add_executable(${PROJECT_NAME} ${SRC_FILES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 14) + +#set warnings +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +else () + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror) +endif () + +find_package(aws-crt-cpp REQUIRED) +find_package(IotIdentity-cpp REQUIRED) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) + +target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-crt-cpp AWS::IotIdentity-cpp) diff --git a/samples/fleet_provisioning/mqtt5_fleet_provisioning/README.md b/samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/README.md similarity index 99% rename from samples/fleet_provisioning/mqtt5_fleet_provisioning/README.md rename to samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/README.md index 9746f5d41..d04d7d1e7 100644 --- a/samples/fleet_provisioning/mqtt5_fleet_provisioning/README.md +++ b/samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/README.md @@ -1,6 +1,6 @@ # Fleet provisioning -[**Return to main sample list**](../../README.md) +[**Return to main sample list**](../../../README.md) This sample uses the AWS IoT [Fleet provisioning](https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html) to provision devices using either a CSR or Keys-And-Certificate and subsequently calls RegisterThing. This allows you to create new AWS IoT Core things using a Fleet Provisioning Template. diff --git a/samples/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp b/samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp similarity index 99% rename from samples/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp rename to samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp index f065fcfd8..ced729bf1 100644 --- a/samples/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp +++ b/samples/deprecated/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp @@ -30,7 +30,7 @@ #include -#include "../../utils/CommandLineUtils.h" +#include "../../../utils/CommandLineUtils.h" using namespace Aws::Crt; using namespace Aws::Iotidentity; diff --git a/samples/deprecated/jobs/job_execution/CMakeLists.txt b/samples/deprecated/jobs/job_execution/CMakeLists.txt new file mode 100644 index 000000000..ebdcaf3fc --- /dev/null +++ b/samples/deprecated/jobs/job_execution/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.9) +# note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12 +project(job-execution CXX) + +file(GLOB SRC_FILES + "*.cpp" + "../../../utils/CommandLineUtils.cpp" + "../../../utils/CommandLineUtils.h" +) + +add_executable(${PROJECT_NAME} ${SRC_FILES}) + +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 14) + +#set warnings +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +else () + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror) +endif () + +find_package(aws-crt-cpp REQUIRED) +find_package(IotJobs-cpp REQUIRED) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) + +target_link_libraries(${PROJECT_NAME} PRIVATE AWS::aws-crt-cpp AWS::IotJobs-cpp) diff --git a/samples/jobs/job_execution/README.md b/samples/deprecated/jobs/job_execution/README.md similarity index 98% rename from samples/jobs/job_execution/README.md rename to samples/deprecated/jobs/job_execution/README.md index 94c093174..d1218c0d6 100644 --- a/samples/jobs/job_execution/README.md +++ b/samples/deprecated/jobs/job_execution/README.md @@ -1,6 +1,6 @@ # Jobs -[**Return to main sample list**](../../README.md) +[**Return to main sample list**](../../../README.md) This sample uses the AWS IoT [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html) Service to describe jobs, it also executes them. [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html) is a service that allows you to define and respond to remote operation requests defined through the AWS IoT Core website or via any other device (or CLI command) that can access the [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html) service. diff --git a/samples/jobs/job_execution/main.cpp b/samples/deprecated/jobs/job_execution/main.cpp similarity index 99% rename from samples/jobs/job_execution/main.cpp rename to samples/deprecated/jobs/job_execution/main.cpp index c26e512a0..a7c3b661f 100644 --- a/samples/jobs/job_execution/main.cpp +++ b/samples/deprecated/jobs/job_execution/main.cpp @@ -30,7 +30,7 @@ #include #include -#include "../../utils/CommandLineUtils.h" +#include "../../../utils/CommandLineUtils.h" using namespace Aws::Crt; using namespace Aws::Iotjobs; diff --git a/samples/jobs/mqtt5_job_execution/CMakeLists.txt b/samples/deprecated/jobs/mqtt5_job_execution/CMakeLists.txt similarity index 89% rename from samples/jobs/mqtt5_job_execution/CMakeLists.txt rename to samples/deprecated/jobs/mqtt5_job_execution/CMakeLists.txt index d6548f57d..bb9c7a2b0 100644 --- a/samples/jobs/mqtt5_job_execution/CMakeLists.txt +++ b/samples/deprecated/jobs/mqtt5_job_execution/CMakeLists.txt @@ -4,8 +4,8 @@ project(mqtt5-job-execution CXX) file(GLOB SRC_FILES "*.cpp" - "../../utils/CommandLineUtils.cpp" - "../../utils/CommandLineUtils.h" + "../../../utils/CommandLineUtils.cpp" + "../../../utils/CommandLineUtils.h" ) add_executable(${PROJECT_NAME} ${SRC_FILES}) diff --git a/samples/jobs/mqtt5_job_execution/README.md b/samples/deprecated/jobs/mqtt5_job_execution/README.md similarity index 99% rename from samples/jobs/mqtt5_job_execution/README.md rename to samples/deprecated/jobs/mqtt5_job_execution/README.md index 6c312729a..9f4305291 100644 --- a/samples/jobs/mqtt5_job_execution/README.md +++ b/samples/deprecated/jobs/mqtt5_job_execution/README.md @@ -1,6 +1,6 @@ # Jobs -[**Return to main sample list**](../../README.md) +[**Return to main sample list**](../../../README.md) This sample uses the AWS IoT [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html) Service to describe jobs to execute, it them executes them. [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html) is a service that allows you to define and respond to remote operation requests defined through the AWS IoT Core website or via any other device (or CLI command) that can access the [Jobs](https://docs.aws.amazon.com/iot/latest/developerguide/iot-jobs.html) service. diff --git a/samples/jobs/mqtt5_job_execution/main.cpp b/samples/deprecated/jobs/mqtt5_job_execution/main.cpp similarity index 99% rename from samples/jobs/mqtt5_job_execution/main.cpp rename to samples/deprecated/jobs/mqtt5_job_execution/main.cpp index 6782ccb8f..37795de3e 100644 --- a/samples/jobs/mqtt5_job_execution/main.cpp +++ b/samples/deprecated/jobs/mqtt5_job_execution/main.cpp @@ -29,7 +29,7 @@ #include #include -#include "../../utils/CommandLineUtils.h" +#include "../../../utils/CommandLineUtils.h" using namespace Aws::Crt; using namespace Aws::Iotjobs; diff --git a/samples/shadow/mqtt5_shadow_sync/CMakeLists.txt b/samples/deprecated/shadow/mqtt5_shadow_sync/CMakeLists.txt similarity index 89% rename from samples/shadow/mqtt5_shadow_sync/CMakeLists.txt rename to samples/deprecated/shadow/mqtt5_shadow_sync/CMakeLists.txt index c901844b1..990081623 100644 --- a/samples/shadow/mqtt5_shadow_sync/CMakeLists.txt +++ b/samples/deprecated/shadow/mqtt5_shadow_sync/CMakeLists.txt @@ -4,8 +4,8 @@ project(mqtt5-shadow-sync CXX) file(GLOB SRC_FILES "*.cpp" - "../../utils/CommandLineUtils.cpp" - "../../utils/CommandLineUtils.h" + "../../../utils/CommandLineUtils.cpp" + "../../../utils/CommandLineUtils.h" ) add_executable(${PROJECT_NAME} ${SRC_FILES}) diff --git a/samples/shadow/mqtt5_shadow_sync/README.md b/samples/deprecated/shadow/mqtt5_shadow_sync/README.md similarity index 99% rename from samples/shadow/mqtt5_shadow_sync/README.md rename to samples/deprecated/shadow/mqtt5_shadow_sync/README.md index 0c614a9e5..27f3348d9 100644 --- a/samples/shadow/mqtt5_shadow_sync/README.md +++ b/samples/deprecated/shadow/mqtt5_shadow_sync/README.md @@ -1,6 +1,6 @@ # Shadow -[**Return to main sample list**](../../README.md) +[**Return to main sample list**](../../../README.md) This sample uses the AWS IoT [Device Shadow](https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html) Service to keep a property in sync between device and server. Imagine a light whose color may be changed through an app, or set by a local user. diff --git a/samples/shadow/mqtt5_shadow_sync/main.cpp b/samples/deprecated/shadow/mqtt5_shadow_sync/main.cpp similarity index 99% rename from samples/shadow/mqtt5_shadow_sync/main.cpp rename to samples/deprecated/shadow/mqtt5_shadow_sync/main.cpp index 515da854c..34f807a19 100644 --- a/samples/shadow/mqtt5_shadow_sync/main.cpp +++ b/samples/deprecated/shadow/mqtt5_shadow_sync/main.cpp @@ -29,7 +29,7 @@ #include #include -#include "../../utils/CommandLineUtils.h" +#include "../../../utils/CommandLineUtils.h" using namespace Aws::Crt; using namespace Aws::Iotshadow; diff --git a/samples/shadow/shadow_sync/CMakeLists.txt b/samples/deprecated/shadow/shadow_sync/CMakeLists.txt similarity index 89% rename from samples/shadow/shadow_sync/CMakeLists.txt rename to samples/deprecated/shadow/shadow_sync/CMakeLists.txt index a19cb868f..0cd7f2db1 100644 --- a/samples/shadow/shadow_sync/CMakeLists.txt +++ b/samples/deprecated/shadow/shadow_sync/CMakeLists.txt @@ -4,8 +4,8 @@ project(shadow-sync CXX) file(GLOB SRC_FILES "*.cpp" - "../../utils/CommandLineUtils.cpp" - "../../utils/CommandLineUtils.h" + "../../../utils/CommandLineUtils.cpp" + "../../../utils/CommandLineUtils.h" ) add_executable(${PROJECT_NAME} ${SRC_FILES}) diff --git a/samples/shadow/shadow_sync/README.md b/samples/deprecated/shadow/shadow_sync/README.md similarity index 98% rename from samples/shadow/shadow_sync/README.md rename to samples/deprecated/shadow/shadow_sync/README.md index 4c687c71d..761183a50 100644 --- a/samples/shadow/shadow_sync/README.md +++ b/samples/deprecated/shadow/shadow_sync/README.md @@ -1,6 +1,6 @@ # Shadow -[**Return to main sample list**](../../README.md) +[**Return to main sample list**](../../../README.md) This sample uses the AWS IoT [Device Shadow](https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html) Service to keep a property in sync between device and server. Imagine a light whose color may be changed through an app, or set by a local user. diff --git a/samples/shadow/shadow_sync/main.cpp b/samples/deprecated/shadow/shadow_sync/main.cpp similarity index 99% rename from samples/shadow/shadow_sync/main.cpp rename to samples/deprecated/shadow/shadow_sync/main.cpp index 3eec289d1..4ba2a228c 100644 --- a/samples/shadow/shadow_sync/main.cpp +++ b/samples/deprecated/shadow/shadow_sync/main.cpp @@ -28,7 +28,7 @@ #include #include -#include "../../utils/CommandLineUtils.h" +#include "../../../utils/CommandLineUtils.h" using namespace Aws::Crt; using namespace Aws::Iotshadow; diff --git a/samples/fleet_provisioning/mqtt5_fleet_provisioning/CMakeLists.txt b/samples/fleet_provisioning/provision-basic/CMakeLists.txt similarity index 95% rename from samples/fleet_provisioning/mqtt5_fleet_provisioning/CMakeLists.txt rename to samples/fleet_provisioning/provision-basic/CMakeLists.txt index 06813d204..f1662043d 100644 --- a/samples/fleet_provisioning/mqtt5_fleet_provisioning/CMakeLists.txt +++ b/samples/fleet_provisioning/provision-basic/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.9...3.31) # note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12 -project(mqtt5-fleet-provisioning CXX) +project(fleet-provisioning-basic CXX) file(GLOB SRC_FILES "*.cpp" diff --git a/samples/fleet_provisioning/provision-basic/README.md b/samples/fleet_provisioning/provision-basic/README.md new file mode 100644 index 000000000..eb91cf679 --- /dev/null +++ b/samples/fleet_provisioning/provision-basic/README.md @@ -0,0 +1,274 @@ +# Fleet provisioning + +[**Return to main sample list**](../../README.md) + +This sample uses the AWS IoT [Fleet provisioning service](https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html) to provision devices using the CreateKeysAndCertificate and RegisterThing APIs. This allows you to create new AWS IoT Core thing resources using a Fleet Provisioning Template. + +You must have a provisioning certificate and key pair whose associated [Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) must provide privileges for this sample to connect as well as subscribe, publish, and receive on MQTT topics used by the provisning APIs that the sample invokes. Below is a sample policy that can be used on your IoT Core Thing that will allow this sample to run as intended. + +
+(see sample policy) +
+{
+  "Version": "2012-10-17",
+  "Statement": [
+    {
+      "Effect": "Allow",
+      "Action": "iot:Publish",
+      "Resource": [
+        "arn:aws:iot:region:account:topic/$aws/certificates/create/json",
+        "arn:aws:iot:region:account:topic/$aws/provisioning-templates/templatename/provision/json"
+      ]
+    },
+    {
+      "Effect": "Allow",
+      "Action": [
+        "iot:Receive"
+      ],
+      "Resource": [
+        "arn:aws:iot:region:account:topic/$aws/certificates/create/json/accepted",
+        "arn:aws:iot:region:account:topic/$aws/certificates/create/json/rejected",
+        "arn:aws:iot:region:account:topic/$aws/provisioning-templates/templatename/provision/json/accepted",
+        "arn:aws:iot:region:account:topic/$aws/provisioning-templates/templatename/provision/json/rejected"
+      ]
+    },
+    {
+      "Effect": "Allow",
+      "Action": [
+        "iot:Subscribe"
+      ],
+      "Resource": [
+        "arn:aws:iot:region:account:topicfilter/$aws/certificates/create/json/accepted",
+        "arn:aws:iot:region:account:topicfilter/$aws/certificates/create/json/rejected",
+        "arn:aws:iot:region:account:topicfilter/$aws/provisioning-templates/templatename/provision/json/accepted",
+        "arn:aws:iot:region:account:topicfilter/$aws/provisioning-templates/templatename/provision/json/rejected"
+      ]
+    },
+    {
+      "Effect": "Allow",
+      "Action": "iot:Connect",
+      "Resource": "arn:aws:iot:region:account:client/test-*"
+    }
+  ]
+}
+
+ +Replace with the following with the data from your AWS account: +* ``: The AWS IoT Core region where you created your AWS IoT Core thing you wish to use with this sample. For example `us-east-1`. +* ``: Your AWS IoT Core account ID. This is the set of numbers in the top right next to your AWS account name when using the AWS IoT Core website. +* ``: The name of your AWS Fleet Provisioning template you want to use to create new AWS IoT Core Things. + +Note that in a real application, you may want to avoid the use of wildcards in your ClientID or use them selectively. Please follow best practices when working with AWS on production applications using the SDK. Also, for the purposes of this sample, please make sure your policy allows a client ID of `test-*` to connect or use `--client_id ` to send the client ID your policy supports. + +
+ +## Fleet Provisioning Detailed Instructions + +### Aws Resource Setup + +Fleet provisioning requires some additional AWS resources be set up first. These steps assume you have the [AWS CLI](https://aws.amazon.com/cli/) installed and have your AWS credentials for the AWS CLI setup and with sufficient permissions to perform all of the operations in this guide. For instructions on how to setup AWS CLI, see the following: [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). The default region used by the CLI must match the region you intend to use; alternatively, you can specify `--region ` as a parameter to all CLI commands. + +If you do not have a provisioning cert and key pair, you will also need Python version 3 installed to be able to run the `parse_cert_set_result.py` file, which is a script used in the process of creating a provisioning certificate and key pair. You can find Python3 installers for your platform on the [Python website](https://www.python.org/). + +These steps are based on the provisioning setup steps +that can be found at [Embedded C SDK Setup](https://docs.aws.amazon.com/freertos/latest/lib-ref/c-sdk/provisioning/provisioning_tests.html#provisioning_system_tests_setup). + + +First, create the IAM role that will be needed by the fleet provisioning template. Replace `` with the name of the role you want to create. + +``` sh +aws iam create-role \ + --role-name \ + --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Action":"sts:AssumeRole","Effect":"Allow","Principal":{"Service":"iot.amazonaws.com"}}]}' +``` + +This is the IAM role the Fleet Provisioning template will use to create the new AWS IoT things. However, before it can do so, it will need to have a policy attached to it to give the new role permission to perform the operations it needs. To do this, run the following command and replace `` with the name of the role you created in the previous step. + +``` sh +aws iam attach-role-policy \ + --role-name \ + --policy-arn arn:aws:iam::aws:policy/service-role/AWSIoTThingsRegistration +``` + +The next step is to make a template resource that will be used for provisioning the new AWS IoT Core things. This template tells AWS IoT Core how to setup the new AWS IoT Core Things you create when your Fleet Provisioning role is invoked, setting up material such as the name and tags, for example. + +To create a new Fleet Provisioning template, you can use the following AWS CLI command, replacing `` with the name of the template you wish to create, `` with the name of the role you created two steps prior, and `` with your AWS IoT Core account number. Finally, make sure to replace `` with a valid JSON document as a single line. An example JSON document is provided further below. + +``` sh +aws iot create-provisioning-template \ + --template-name \ + --provisioning-role-arn arn:aws:iam:::role/ \ + --template-body "" \ + --enabled +``` + +For the purposes of this sample, the following template JSON document is presumed to be used: + +
+(see template body) + +```json +{ + "Parameters": { + "DeviceLocation": { + "Type": "String" + }, + "AWS::IoT::Certificate::Id": { + "Type": "String" + }, + "SerialNumber": { + "Type": "String" + } + }, + "Mappings": { + "LocationTable": { + "Seattle": { + "LocationUrl": "https://example.aws" + } + } + }, + "Resources": { + "thing": { + "Type": "AWS::IoT::Thing", + "Properties": { + "ThingName": { + "Fn::Join": [ + "", + [ + "ThingPrefix_", + { + "Ref": "SerialNumber" + } + ] + ] + }, + "AttributePayload": { + "version": "v1", + "serialNumber": "serialNumber" + } + }, + "OverrideSettings": { + "AttributePayload": "MERGE", + "ThingTypeName": "REPLACE", + "ThingGroups": "DO_NOTHING" + } + }, + "certificate": { + "Type": "AWS::IoT::Certificate", + "Properties": { + "CertificateId": { + "Ref": "AWS::IoT::Certificate::Id" + }, + "Status": "Active" + }, + "OverrideSettings": { + "Status": "REPLACE" + } + }, + "policy": { + "Type": "AWS::IoT::Policy", + "Properties": { + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "iot:Connect", + "iot:Subscribe", + "iot:Publish", + "iot:Receive" + ], + "Resource": "*" + } + ] + } + } + } + }, + "DeviceConfiguration": { + "FallbackUrl": "https://www.example.com/test-site", + "LocationUrl": { + "Fn::FindInMap": [ + "LocationTable", + { + "Ref": "DeviceLocation" + }, + "LocationUrl" + ] + } + } +} +``` + +
+ +And here is the same JSON document, but as a single line for easier copy-pasting: + +
+(see template body) + +``` json +{"Parameters": {"DeviceLocation": {"Type": "String"},"AWS::IoT::Certificate::Id": {"Type": "String"},"SerialNumber": {"Type": "String"}},"Mappings": {"LocationTable": {"Seattle": {"LocationUrl": "https://example.aws"}}},"Resources": {"thing": {"Type": "AWS::IoT::Thing","Properties": {"ThingName": {"Fn::Join": ["",["ThingPrefix_",{"Ref": "SerialNumber"}]]},"AttributePayload": {"version": "v1","serialNumber": "serialNumber"}},"OverrideSettings": {"AttributePayload": "MERGE","ThingTypeName": "REPLACE","ThingGroups": "DO_NOTHING"}},"certificate": {"Type": "AWS::IoT::Certificate","Properties": {"CertificateId": {"Ref": "AWS::IoT::Certificate::Id"},"Status": "Active"},"OverrideSettings": {"Status": "REPLACE"}},"policy": {"Type": "AWS::IoT::Policy","Properties": {"PolicyDocument": {"Version": "2012-10-17","Statement": [{"Effect": "Allow","Action": ["iot:Connect","iot:Subscribe","iot:Publish","iot:Receive"],"Resource": "*"}]}}}},"DeviceConfiguration": {"FallbackUrl": "https://www.example.com/test-site","LocationUrl": {"Fn::FindInMap": ["LocationTable",{"Ref": "DeviceLocation"},"LocationUrl"]}}} +``` + +
+ +You can use this JSON document as the `` in the AWS CLI command. This sample will assume you have used the template JSON above, so you may need to adjust if you are using a different template JSON. Thankfully, all of these steps need to only be done and, now that they are complete, you will need not perform them again. + +### Creating a provisioning certificate and key pair from a provisioning claim + +To run the provisioning sample, you'll need a provisioning certificate and key set with sufficient permissions (see the policy at the top). Provisioning certificates are normally created ahead of time and placed on your device, but for this sample, we will just create them on the fly. This is primarily done for example purposes. + +You can also use any certificate set you've already created if it has sufficient IoT permissions. If you wish to do this, you can skip the step that calls `create-provisioning-claim` below and move right to the next step: [Running the sample using a certificate-key set](#running-the-sample-using-a-certificate-key-set) + +We've included a script in the utils folder that creates certificate and key files from the response of calling +`create-provisioning-claim`. These dynamically sourced certificates are **only valid for five minutes**. When running the command, +you'll need to substitute the name of the template you previously created. If on Windows, replace the paths with something appropriate. + +**Note**: The following assumes you are running this command from the `aws-iot-device-sdk-cpp-v2` folder (SDK root) . If you are running this from another folder then you will need to adjust the filepaths accordingly. + +```sh +aws iot create-provisioning-claim \ + --template-name \ + | python3 ./utils/parse_cert_set_result.py \ + --path /tmp \ + --filename provision +``` +* Replace `` with the name of the Fleet Provisioning template you created earlier. + +This will create a certificate and key in the `tmp` folder with file names starting with `provision`. You can now use these temporary keys +to perform the actual provisioning in the section below. + +### Build and run the sample + +Before building and running the sample, you must first build and install the SDK: + +``` sh +cd +mkdir _build +cd _build +cmake -DCMAKE_INSTALL_PREFIX= .. +make && make install +``` + +Now build the sample: + +``` sh +cd samples/fleet_provisioning/provision-basic +mkdir _build +cd _build +cmake -DCMAKE_PREFIX_PATH= .. +make +``` + +To run the sample: + +``` sh +./fleet-provisioning-basic --endpoint --cert --key --template_name