Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc. GitHub
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan DeleteTopicRule dengan AWS SDK atau CLI
Contoh kode berikut menunjukkan cara menggunakanDeleteTopicRule.
Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:
- C++
-
- SDK untuk C++
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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();
}
- CLI
-
- AWS CLI
-
Untuk menghapus aturan
delete-topic-ruleContoh berikut menghapus aturan yang ditentukan.
aws iot delete-topic-rule \
--rule-name "LowMoistureRule"
Perintah ini tidak menghasilkan output.
Untuk informasi selengkapnya, lihat Menghapus Aturan di Panduan Pengembang AWS IoT.
- Python
-
- SDK untuk Python (Boto3)
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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