本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DeleteTopicRule 搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 DeleteTopicRule。
- C++
-
- SDK for C++
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 //! 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(); }-
如需 API 詳細資訊,請參閱《適用於 C++ 的 AWS SDK API 參考》中的 DeleteTopicRule。
-
- CLI
-
- AWS CLI
-
刪除規則
以下
delete-topic-rule範例會刪除指定規則。aws iot delete-topic-rule \ --rule-name"LowMoistureRule"此命令不會產生輸出。
如需詳細資訊,請參閱《AWS IoT 開發人員指南》中的刪除規則。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DeleteTopicRule
。
-
- Python
-
- 適用於 Python 的 SDK (Boto3)
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 class IoTWrapper: """Encapsulates AWS IoT actions.""" def __init__(self, iot_client, iot_data_client=None): """ :param iot_client: A Boto3 AWS IoT client. :param iot_data_client: A Boto3 AWS IoT Data Plane client. """ self.iot_client = iot_client self.iot_data_client = iot_data_client @classmethod def from_client(cls): iot_client = boto3.client("iot") iot_data_client = boto3.client("iot-data") return cls(iot_client, iot_data_client) def delete_topic_rule(self, rule_name): """ Deletes an AWS IoT topic rule. :param rule_name: The name of the rule to delete. """ try: self.iot_client.delete_topic_rule(ruleName=rule_name) logger.info("Deleted topic rule %s.", rule_name) except ClientError as err: logger.error( "Couldn't delete topic rule. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise-
如需 API 詳細資訊,請參閱《適用於 AWS Python (Boto3) 的 SDK API 參考》中的 DeleteTopicRule。
-
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 AWS IoT 搭配 AWS SDK 使用。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。
DeleteThing
DescribeEndpoint