Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use DeleteTopicRule with an Amazon SDK or CLI
The following code examples show how to use DeleteTopicRule.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code example:
- C++
-
- SDK for C++
-
//! 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
-
- Amazon CLI
-
To delete a rule
The following delete-topic-rule example deletes the specified rule.
aws iot delete-topic-rule \
--rule-name "LowMoistureRule"
This command produces no output.
For more information, see Deleting a Rule in the Amazon IoT Developers Guide.
- Python
-
- SDK for Python (Boto3)
-
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
- SAP ABAP
-
- SDK for SAP ABAP
-
CONSTANTS cv_pfl TYPE /aws1/rt_profile_id VALUE 'ZCODE_DEMO'.
DATA(lo_session) = /aws1/cl_rt_session_aws=>create( cv_pfl ).
DATA(lo_iot) = /aws1/cl_iot_factory=>create( lo_session ).
TRY.
lo_iot->deletetopicrule( iv_rulename = iv_rule_name ).
MESSAGE |IoT topic rule deleted: { iv_rule_name }| TYPE 'I'.
CATCH /aws1/cx_rt_service_generic INTO DATA(lo_ex).
MESSAGE lo_ex->get_text( ) TYPE 'I'.
RAISE EXCEPTION lo_ex.
ENDTRY.
For a complete list of Amazon SDK developer guides and code examples, see
Using Amazon IoT with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.