Weitere AWS SDK-Beispiele sind im Repo AWS Doc SDK Examples
Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.
Erlernen Sie die Grundlagen von AWS IoT mit einem SDK AWS
Die folgenden Codebeispiele zeigen, wie Sie mit der AWS IoT Geräteverwaltung arbeiten.
- SDK für C++
-
Anmerkung
Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository
einrichten und ausführen. Erschaffe AWS IoT etwas.
Aws::String thingName = askQuestion("Enter a thing name: "); if (!createThing(thingName, clientConfiguration)) { std::cerr << "Exiting because createThing failed." << std::endl; cleanup("", "", "", "", "", false, clientConfiguration); return false; }
//! Create an AWS IoT thing. /*! \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::createThing(const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::CreateThingRequest createThingRequest; createThingRequest.SetThingName(thingName); Aws::IoT::Model::CreateThingOutcome outcome = iotClient.CreateThing( createThingRequest); if (outcome.IsSuccess()) { std::cout << "Successfully created thing " << thingName << std::endl; } else { std::cerr << "Failed to create thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
Generieren Sie ein Gerätezertifikat und hängen Sie es an.
Aws::String certificateARN; Aws::String certificateID; if (askYesNoQuestion("Would you like to create a certificate for your thing? (y/n) ")) { Aws::String outputFolder; if (askYesNoQuestion( "Would you like to save the certificate and keys to file? (y/n) ")) { outputFolder = std::filesystem::current_path(); outputFolder += "/device_keys_and_certificates"; std::filesystem::create_directories(outputFolder); std::cout << "The certificate and keys will be saved to the folder: " << outputFolder << std::endl; } if (!createKeysAndCertificate(outputFolder, certificateARN, certificateID, clientConfiguration)) { std::cerr << "Exiting because createKeysAndCertificate failed." << std::endl; cleanup(thingName, "", "", "", "", false, clientConfiguration); return false; } std::cout << "\nNext, the certificate will be attached to the thing.\n" << std::endl; if (!attachThingPrincipal(certificateARN, thingName, clientConfiguration)) { std::cerr << "Exiting because attachThingPrincipal failed." << std::endl; cleanup(thingName, certificateARN, certificateID, "", "", false, clientConfiguration); return false; } }
//! Create keys and certificate for an Aws IoT device. //! This routine will save certificates and keys to an output folder, if provided. /*! \param outputFolder: Location for storing output in files, ignored when string is empty. \param certificateARNResult: A string to receive the ARN of the created certificate. \param certificateID: A string to receive the ID of the created certificate. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::createKeysAndCertificate(const Aws::String &outputFolder, Aws::String &certificateARNResult, Aws::String &certificateID, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient client(clientConfiguration); Aws::IoT::Model::CreateKeysAndCertificateRequest createKeysAndCertificateRequest; Aws::IoT::Model::CreateKeysAndCertificateOutcome outcome = client.CreateKeysAndCertificate(createKeysAndCertificateRequest); if (outcome.IsSuccess()) { std::cout << "Successfully created a certificate and keys" << std::endl; certificateARNResult = outcome.GetResult().GetCertificateArn(); certificateID = outcome.GetResult().GetCertificateId(); std::cout << "Certificate ARN: " << certificateARNResult << ", certificate ID: " << certificateID << std::endl; if (!outputFolder.empty()) { std::cout << "Writing certificate and keys to the folder '" << outputFolder << "'." << std::endl; std::cout << "Be sure these files are stored securely." << std::endl; Aws::String certificateFilePath = outputFolder + "/certificate.pem.crt"; std::ofstream certificateFile(certificateFilePath); if (!certificateFile.is_open()) { std::cerr << "Error opening certificate file, '" << certificateFilePath << "'." << std::endl; return false; } certificateFile << outcome.GetResult().GetCertificatePem(); certificateFile.close(); const Aws::IoT::Model::KeyPair &keyPair = outcome.GetResult().GetKeyPair(); Aws::String privateKeyFilePath = outputFolder + "/private.pem.key"; std::ofstream privateKeyFile(privateKeyFilePath); if (!privateKeyFile.is_open()) { std::cerr << "Error opening private key file, '" << privateKeyFilePath << "'." << std::endl; return false; } privateKeyFile << keyPair.GetPrivateKey(); privateKeyFile.close(); Aws::String publicKeyFilePath = outputFolder + "/public.pem.key"; std::ofstream publicKeyFile(publicKeyFilePath); if (!publicKeyFile.is_open()) { std::cerr << "Error opening public key file, '" << publicKeyFilePath << "'." << std::endl; return false; } publicKeyFile << keyPair.GetPublicKey(); } } else { std::cerr << "Error creating keys and certificate: " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! Attach a principal to an AWS IoT thing. /*! \param principal: A principal to attach. \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::attachThingPrincipal(const Aws::String &principal, const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient client(clientConfiguration); Aws::IoT::Model::AttachThingPrincipalRequest request; request.SetPrincipal(principal); request.SetThingName(thingName); Aws::IoT::Model::AttachThingPrincipalOutcome outcome = client.AttachThingPrincipal( request); if (outcome.IsSuccess()) { std::cout << "Successfully attached principal to thing." << std::endl; } else { std::cerr << "Failed to attach principal to thing." << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
Führen Sie verschiedene Operationen an dem AWS IoT Ding durch.
if (!updateThing(thingName, { {"location", "Office"}, {"firmwareVersion", "v2.0"} }, clientConfiguration)) { std::cerr << "Exiting because updateThing failed." << std::endl; cleanup(thingName, certificateARN, certificateID, "", "", false, clientConfiguration); return false; } printAsterisksLine(); std::cout << "Now an endpoint will be retrieved for your account.\n" << std::endl; std::cout << "An IoT Endpoint refers to a specific URL or Uniform Resource Locator that serves as the entry point\n" << "for communication between IoT devices and the AWS IoT service." << std::endl; askQuestion("Press Enter to continue:", alwaysTrueTest); Aws::String endpoint; if (!describeEndpoint(endpoint, clientConfiguration)) { std::cerr << "Exiting because getEndpoint failed." << std::endl; cleanup(thingName, certificateARN, certificateID, "", "", false, clientConfiguration); return false; } std::cout <<"Your endpoint is " << endpoint << "." << std::endl; printAsterisksLine(); std::cout << "Now the certificates in your account will be listed." << std::endl; askQuestion("Press Enter to continue:", alwaysTrueTest); if (!listCertificates(clientConfiguration)) { std::cerr << "Exiting because listCertificates failed." << std::endl; cleanup(thingName, certificateARN, certificateID, "", "", false, clientConfiguration); return false; } printAsterisksLine(); std::cout << "Now the shadow for the thing will be updated.\n" << std::endl; std::cout << "A thing shadow refers to a feature that enables you to create a virtual representation, or \"shadow,\"\n" << "of a physical device or thing. The thing shadow allows you to synchronize and control the state of a device between\n" << "the cloud and the device itself. and the AWS IoT service. For example, you can write and retrieve JSON data from a thing shadow." << std::endl; askQuestion("Press Enter to continue:", alwaysTrueTest); if (!updateThingShadow(thingName, R"({"state":{"reported":{"temperature":25,"humidity":50}}})", clientConfiguration)) { std::cerr << "Exiting because updateThingShadow failed." << std::endl; cleanup(thingName, certificateARN, certificateID, "", "", false, clientConfiguration); return false; } printAsterisksLine(); std::cout << "Now, the state information for the shadow will be retrieved.\n" << std::endl; askQuestion("Press Enter to continue:", alwaysTrueTest); Aws::String shadowState; if (!getThingShadow(thingName, shadowState, clientConfiguration)) { std::cerr << "Exiting because getThingShadow failed." << std::endl; cleanup(thingName, certificateARN, certificateID, "", "", false, clientConfiguration); return false; } std::cout << "The retrieved shadow state is: " << shadowState << std::endl; printAsterisksLine(); std::cout << "A rule with now be added to to the thing.\n" << std::endl; std::cout << "Any user who has permission to create rules will be able to access data processed by the rule." << std::endl; std::cout << "In this case, the rule will use an Simple Notification Service (SNS) topic and an IAM rule." << std::endl; std::cout << "These resources will be created using a CloudFormation template." << std::endl; std::cout << "Stack creation may take a few minutes." << std::endl; askQuestion("Press Enter to continue: ", alwaysTrueTest); Aws::Map<Aws::String, Aws::String> outputs =createCloudFormationStack(STACK_NAME,clientConfiguration); if (outputs.empty()) { std::cerr << "Exiting because createCloudFormationStack failed." << std::endl; cleanup(thingName, certificateARN, certificateID, "", "", false, clientConfiguration); return false; } // Retrieve the topic ARN and role ARN from the CloudFormation stack outputs. auto topicArnIter = outputs.find(SNS_TOPIC_ARN_OUTPUT); auto roleArnIter = outputs.find(ROLE_ARN_OUTPUT); if ((topicArnIter == outputs.end()) || (roleArnIter == outputs.end())) { std::cerr << "Exiting because output '" << SNS_TOPIC_ARN_OUTPUT << "' or '" << ROLE_ARN_OUTPUT << "'not found in the CloudFormation stack." << std::endl; cleanup(thingName, certificateARN, certificateID, STACK_NAME, "", false, clientConfiguration); return false; } Aws::String topicArn = topicArnIter->second; Aws::String roleArn = roleArnIter->second; Aws::String sqlStatement = "SELECT * FROM '"; sqlStatement += MQTT_MESSAGE_TOPIC_FILTER; sqlStatement += "'"; printAsterisksLine(); std::cout << "Now a rule will be created.\n" << std::endl; std::cout << "Rules are an administrator-level action. Any user who has permission\n" << "to create rules will be able to access data processed by the rule." << std::endl; std::cout << "In this case, the rule will use an SNS topic" << std::endl; std::cout << "and the following SQL statement '" << sqlStatement << "'." << std::endl; std::cout << "For more information on IoT SQL, see https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-reference.html" << std::endl; Aws::String ruleName = askQuestion("Enter a rule name: "); if (!createTopicRule(ruleName, topicArn, sqlStatement, roleArn, clientConfiguration)) { std::cerr << "Exiting because createRule failed." << std::endl; cleanup(thingName, certificateARN, certificateID, STACK_NAME, "", false, clientConfiguration); return false; } printAsterisksLine(); std::cout << "Now your rules will be listed.\n" << std::endl; askQuestion("Press Enter to continue: ", alwaysTrueTest); if (!listTopicRules(clientConfiguration)) { std::cerr << "Exiting because listRules failed." << std::endl; cleanup(thingName, certificateARN, certificateID, STACK_NAME, ruleName, false, clientConfiguration); return false; } printAsterisksLine(); Aws::String queryString = "thingName:" + thingName; std::cout << "Now the AWS IoT fleet index will be queried with the query\n'" << queryString << "'.\n" << std::endl; std::cout << "For query information, see https://docs.aws.amazon.com/iot/latest/developerguide/query-syntax.html" << std::endl; std::cout << "For this query to work, thing indexing must be enabled in your account.\n" << "This can be done with the awscli command line by calling 'aws iot update-indexing-configuration'\n" << "or it can be done programmatically." << std::endl; std::cout << "For more information, see https://docs.aws.amazon.com/iot/latest/developerguide/managing-index.html" << std::endl; if (askYesNoQuestion("Do you want to enable thing indexing in your account? (y/n) ")) { Aws::IoT::Model::ThingIndexingConfiguration thingIndexingConfiguration; thingIndexingConfiguration.SetThingIndexingMode(Aws::IoT::Model::ThingIndexingMode::REGISTRY_AND_SHADOW); thingIndexingConfiguration.SetThingConnectivityIndexingMode(Aws::IoT::Model::ThingConnectivityIndexingMode::STATUS); // The ThingGroupIndexingConfiguration object is ignored if not set. Aws::IoT::Model::ThingGroupIndexingConfiguration thingGroupIndexingConfiguration; if (!updateIndexingConfiguration(thingIndexingConfiguration, thingGroupIndexingConfiguration, clientConfiguration)) { std::cerr << "Exiting because updateIndexingConfiguration failed." << std::endl; cleanup(thingName, certificateARN, certificateID, STACK_NAME, ruleName, false, clientConfiguration); return false; } } if (!searchIndex(queryString, clientConfiguration)) { std::cerr << "Exiting because searchIndex failed." << std::endl; cleanup(thingName, certificateARN, certificateID, STACK_NAME, ruleName, false, clientConfiguration); return false; }
//! Update an AWS IoT thing with attributes. /*! \param thingName: The name for the thing. \param attributeMap: A map of key/value attributes/ \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::updateThing(const Aws::String &thingName, const std::map<Aws::String, Aws::String> &attributeMap, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::UpdateThingRequest request; request.SetThingName(thingName); Aws::IoT::Model::AttributePayload attributePayload; for (const auto &attribute: attributeMap) { attributePayload.AddAttributes(attribute.first, attribute.second); } request.SetAttributePayload(attributePayload); Aws::IoT::Model::UpdateThingOutcome outcome = iotClient.UpdateThing(request); if (outcome.IsSuccess()) { std::cout << "Successfully updated thing " << thingName << std::endl; } else { std::cerr << "Failed to update thing " << thingName << ":" << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! Describe the endpoint specific to the AWS account making the call. /*! \param endpointResult: String to receive the endpoint result. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::describeEndpoint(Aws::String &endpointResult, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::String endpoint; Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DescribeEndpointRequest describeEndpointRequest; describeEndpointRequest.SetEndpointType( "iot:Data-ATS"); // Recommended endpoint type. Aws::IoT::Model::DescribeEndpointOutcome outcome = iotClient.DescribeEndpoint( describeEndpointRequest); if (outcome.IsSuccess()) { std::cout << "Successfully described endpoint." << std::endl; endpointResult = outcome.GetResult().GetEndpointAddress(); } else { std::cerr << "Error describing endpoint" << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! List certificates registered in the AWS account making the call. /*! \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::listCertificates( const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::ListCertificatesRequest request; Aws::Vector<Aws::IoT::Model::Certificate> allCertificates; Aws::String marker; // Used to paginate results. do { if (!marker.empty()) { request.SetMarker(marker); } Aws::IoT::Model::ListCertificatesOutcome outcome = iotClient.ListCertificates( request); if (outcome.IsSuccess()) { const Aws::IoT::Model::ListCertificatesResult &result = outcome.GetResult(); marker = result.GetNextMarker(); allCertificates.insert(allCertificates.end(), result.GetCertificates().begin(), result.GetCertificates().end()); } else { std::cerr << "Error: " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!marker.empty()); std::cout << allCertificates.size() << " certificate(s) found." << std::endl; for (auto &certificate: allCertificates) { std::cout << "Certificate ID: " << certificate.GetCertificateId() << std::endl; std::cout << "Certificate ARN: " << certificate.GetCertificateArn() << std::endl; std::cout << std::endl; } return true; } //! Update the shadow of an AWS IoT thing. /*! \param thingName: The name for the thing. \param document: The state information, in JSON format. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::updateThingShadow(const Aws::String &thingName, const Aws::String &document, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoTDataPlane::IoTDataPlaneClient iotDataPlaneClient(clientConfiguration); Aws::IoTDataPlane::Model::UpdateThingShadowRequest updateThingShadowRequest; updateThingShadowRequest.SetThingName(thingName); std::shared_ptr<std::stringstream> streamBuf = std::make_shared<std::stringstream>( document); updateThingShadowRequest.SetBody(streamBuf); Aws::IoTDataPlane::Model::UpdateThingShadowOutcome outcome = iotDataPlaneClient.UpdateThingShadow( updateThingShadowRequest); if (outcome.IsSuccess()) { std::cout << "Successfully updated thing shadow." << std::endl; } else { std::cerr << "Error while updating thing shadow." << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! Get the shadow of an AWS IoT thing. /*! \param thingName: The name for the thing. \param documentResult: String to receive the state information, in JSON format. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::getThingShadow(const Aws::String &thingName, Aws::String &documentResult, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoTDataPlane::IoTDataPlaneClient iotClient(clientConfiguration); Aws::IoTDataPlane::Model::GetThingShadowRequest request; request.SetThingName(thingName); auto outcome = iotClient.GetThingShadow(request); if (outcome.IsSuccess()) { std::stringstream ss; ss << outcome.GetResult().GetPayload().rdbuf(); documentResult = ss.str(); } else { std::cerr << "Error getting thing shadow: " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! Create an AWS IoT rule with an SNS topic as the target. /*! \param ruleName: The name for the rule. \param snsTopic: The SNS topic ARN for the action. \param sql: The SQL statement used to query the topic. \param roleARN: The IAM role ARN for the action. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::createTopicRule(const Aws::String &ruleName, const Aws::String &snsTopicARN, const Aws::String &sql, const Aws::String &roleARN, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::CreateTopicRuleRequest request; request.SetRuleName(ruleName); Aws::IoT::Model::SnsAction snsAction; snsAction.SetTargetArn(snsTopicARN); snsAction.SetRoleArn(roleARN); Aws::IoT::Model::Action action; action.SetSns(snsAction); Aws::IoT::Model::TopicRulePayload topicRulePayload; topicRulePayload.SetSql(sql); topicRulePayload.SetActions({action}); request.SetTopicRulePayload(topicRulePayload); auto outcome = iotClient.CreateTopicRule(request); if (outcome.IsSuccess()) { std::cout << "Successfully created topic rule " << ruleName << "." << std::endl; } else { std::cerr << "Error creating topic rule " << ruleName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! Lists the AWS IoT topic rules. /*! \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::listTopicRules( const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::ListTopicRulesRequest request; Aws::Vector<Aws::IoT::Model::TopicRuleListItem> allRules; Aws::String nextToken; // Used for pagination. do { if (!nextToken.empty()) { request.SetNextToken(nextToken); } Aws::IoT::Model::ListTopicRulesOutcome outcome = iotClient.ListTopicRules( request); if (outcome.IsSuccess()) { const Aws::IoT::Model::ListTopicRulesResult &result = outcome.GetResult(); allRules.insert(allRules.end(), result.GetRules().cbegin(), result.GetRules().cend()); nextToken = result.GetNextToken(); } else { std::cerr << "ListTopicRules error: " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!nextToken.empty()); std::cout << "ListTopicRules: " << allRules.size() << " rule(s) found." << std::endl; for (auto &rule: allRules) { std::cout << " Rule name: " << rule.GetRuleName() << ", rule ARN: " << rule.GetRuleArn() << "." << std::endl; } return true; } //! Query the AWS IoT fleet index. //! For query information, see https://docs.aws.amazon.com/iot/latest/developerguide/query-syntax.html /*! \param: query: The query string. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::searchIndex(const Aws::String &query, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::SearchIndexRequest request; request.SetQueryString(query); Aws::Vector<Aws::IoT::Model::ThingDocument> allThingDocuments; Aws::String nextToken; // Used for pagination. do { if (!nextToken.empty()) { request.SetNextToken(nextToken); } Aws::IoT::Model::SearchIndexOutcome outcome = iotClient.SearchIndex(request); if (outcome.IsSuccess()) { const Aws::IoT::Model::SearchIndexResult &result = outcome.GetResult(); allThingDocuments.insert(allThingDocuments.end(), result.GetThings().cbegin(), result.GetThings().cend()); nextToken = result.GetNextToken(); } else { std::cerr << "Error in SearchIndex: " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!nextToken.empty()); std::cout << allThingDocuments.size() << " thing document(s) found." << std::endl; for (const auto thingDocument: allThingDocuments) { std::cout << " Thing name: " << thingDocument.GetThingName() << "." << std::endl; } return true; }
Bereinigen von Ressourcen.
bool AwsDoc::IoT::cleanup(const Aws::String &thingName, const Aws::String &certificateARN, const Aws::String &certificateID, const Aws::String &stackName, const Aws::String &ruleName, bool askForConfirmation, const Aws::Client::ClientConfiguration &clientConfiguration) { bool result = true; if (!ruleName.empty() && (!askForConfirmation || askYesNoQuestion("Delete the rule '" + ruleName + "'? (y/n) "))) { result &= deleteTopicRule(ruleName, clientConfiguration); } Aws::CloudFormation::CloudFormationClient cloudFormationClient(clientConfiguration); if (!stackName.empty() && (!askForConfirmation || askYesNoQuestion( "Delete the CloudFormation stack '" + stackName + "'? (y/n) "))) { result &= deleteStack(stackName, clientConfiguration); } if (!certificateARN.empty() && (!askForConfirmation || askYesNoQuestion("Delete the certificate '" + certificateARN + "'? (y/n) "))) { result &= detachThingPrincipal(certificateARN, thingName, clientConfiguration); result &= deleteCertificate(certificateID, clientConfiguration); } if (!thingName.empty() && (!askForConfirmation || askYesNoQuestion("Delete the thing '" + thingName + "'? (y/n) "))) { result &= deleteThing(thingName, clientConfiguration); } return result; }
//! Detach a principal from an AWS IoT thing. /*! \param principal: A principal to detach. \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::detachThingPrincipal(const Aws::String &principal, const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DetachThingPrincipalRequest detachThingPrincipalRequest; detachThingPrincipalRequest.SetThingName(thingName); detachThingPrincipalRequest.SetPrincipal(principal); Aws::IoT::Model::DetachThingPrincipalOutcome outcome = iotClient.DetachThingPrincipal( detachThingPrincipalRequest); if (outcome.IsSuccess()) { std::cout << "Successfully detached principal " << principal << " from thing " << thingName << std::endl; } else { std::cerr << "Failed to detach principal " << principal << " from thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! Delete a certificate. /*! \param certificateID: The ID of a certificate. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::deleteCertificate(const Aws::String &certificateID, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DeleteCertificateRequest request; request.SetCertificateId(certificateID); Aws::IoT::Model::DeleteCertificateOutcome outcome = iotClient.DeleteCertificate( request); if (outcome.IsSuccess()) { std::cout << "Successfully deleted certificate " << certificateID << std::endl; } else { std::cerr << "Error deleting certificate " << certificateID << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! Delete an AWS IoT rule. /*! \param ruleName: The name for the rule. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::deleteTopicRule(const Aws::String &ruleName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DeleteTopicRuleRequest request; request.SetRuleName(ruleName); Aws::IoT::Model::DeleteTopicRuleOutcome outcome = iotClient.DeleteTopicRule( request); if (outcome.IsSuccess()) { std::cout << "Successfully deleted rule " << ruleName << std::endl; } else { std::cerr << "Failed to delete rule " << ruleName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } //! Delete an AWS IoT thing. /*! \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::deleteThing(const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DeleteThingRequest request; request.SetThingName(thingName); const auto outcome = iotClient.DeleteThing(request); if (outcome.IsSuccess()) { std::cout << "Successfully deleted thing " << thingName << std::endl; } else { std::cerr << "Error deleting thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }