-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aws-iot-device-sdk-cpp-v2: add fleet provisoning example
- Loading branch information
1 parent
2f527cd
commit 2084fe0
Showing
3 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
recipes-sdk/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning.bb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# nooelint: oelint.file.underscores | ||
require aws-iot-device-sdk-cpp-v2-samples.inc | ||
|
||
S = "${WORKDIR}/git/samples/fleet_provisioning/fleet_provisioning" | ||
|
||
SRC_URI:append = " \ | ||
file://run-ptest \ | ||
" | ||
|
||
RDEPENDS:${PN}-ptest += "python3 aws-cli" | ||
|
||
do_install() { | ||
install -d ${D}${bindir} | ||
install ${B}/fleet-provisioning ${D}${bindir} | ||
} | ||
|
||
inherit ptest pkgconfig | ||
|
||
do_install_ptest() { | ||
install -d ${D}${PTEST_PATH}/tests | ||
|
||
install -m 0755 ${S}/../../../utils/parse_cert_set_result.py ${D}${PTEST_PATH}/ | ||
|
||
install -m 0755 ${WORKDIR}/run-ptest ${D}${PTEST_PATH}/ | ||
} |
35 changes: 35 additions & 0 deletions
35
...k/aws-iot-device-sdk-cpp-v2/aws-iot-device-sdk-cpp-v2-samples-fleet-provisoning/run-ptest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
set -euxo pipefail | ||
echo "nameserver 8.8.8.8" > /etc/resolv.conf | ||
|
||
DATE=$(date "+%F_%H-%M-%S") | ||
ROLE="fprole_$DATE" | ||
TEMPLATE="fptemplate_$DATE" | ||
AWS_ACCOUNT_NUMBER=$(aws sts get-caller-identity --query "Account" --output text) | ||
TEMPLATE_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"]}}}' | ||
IOT_DATA_ENDPOINT=`aws --output text iot describe-endpoint --endpoint-type iot:Data-ATS` | ||
|
||
aws iam create-role \ | ||
--role-name $ROLE \ | ||
--assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Action":"sts:AssumeRole","Effect":"Allow","Principal":{"Service":"iot.amazonaws.com"}}]}' | ||
|
||
aws iam attach-role-policy \ | ||
--role-name $ROLE \ | ||
--policy-arn arn:aws:iam::aws:policy/service-role/AWSIoTThingsRegistration | ||
|
||
# wait for role to be populated | ||
sleep 10 | ||
|
||
aws iot create-provisioning-template \ | ||
--template-name $TEMPLATE \ | ||
--provisioning-role-arn arn:aws:iam::$AWS_ACCOUNT_NUMBER:role/$ROLE \ | ||
--template-body $TEMPLATE_JSON \ | ||
--enabled | ||
|
||
aws iot create-provisioning-claim \ | ||
--template-name $TEMPLATE \ | ||
| python3 ./parse_cert_set_result.py \ | ||
--path ./tmp \ | ||
--filename provision | ||
|
||
fleet-provisioning --endpoint $IOT_DATA_ENDPOINT --cert ./tmp/provision.cert.pem --key ./tmp/provision.private.key --template_name $TEMPLATE --template_parameters '{"SerialNumber":"'$DATE'","DeviceLocation":"Seattle"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters