Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-iot-device-sdk-cpp-v2: add fleet provisoning example #8987

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}/
}
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"}'
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ FILES_SOLIBSDEV = ""
# enable PACKAGECONFIG = "static" to build static instead of shared libs
PACKAGECONFIG[static] = "-DBUILD_SHARED_LIBS=OFF,-DBUILD_SHARED_LIBS=ON,,"

# this does not work because: https://github.com/aws/aws-iot-device-sdk-cpp-v2/issues/393
# PACKAGECONFIG ??= "\
# ${@bb.utils.contains('PTEST_ENABLED', '1', 'with-tests', '', d)} \
# "
# PACKAGECONFIG[with-tests] = "-DBUILD_TESTING=ON,-DBUILD_TESTING=OFF,"
PACKAGECONFIG ??= "\
${@bb.utils.contains('PTEST_ENABLED', '1', 'with-tests', '', d)} \
"
PACKAGECONFIG[with-tests] = "-DBUILD_TESTING=ON,-DBUILD_TESTING=OFF,"

FILES:${PN}-dev += "${libdir}/*/cmake"

RDEPENDS:${PN}-ptest:prepend = "\
RDEPENDS:${PN}-ptest += "\
aws-iot-device-sdk-cpp-v2-samples-mqtt5-pubsub \
"
"

BBCLASSEXTEND = "native nativesdk"
Loading