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 DeleteRule
with an Amazon SDK or command line tool
The following code examples show how to use DeleteRule
.
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:
- .NET
-
- Amazon SDK for .NET
-
Delete a rule by its name.
/// <summary>
/// Delete an event rule by name.
/// </summary>
/// <param name="ruleName">The name of the event rule.</param>
/// <returns>True if successful.</returns>
public async Task<bool> DeleteRuleByName(string ruleName)
{
var response = await _amazonEventBridge.DeleteRuleAsync(
new DeleteRuleRequest()
{
Name = ruleName
});
return response.HttpStatusCode == HttpStatusCode.OK;
}
- CLI
-
- Amazon CLI
-
To delete a CloudWatch Events rule
This example deletes the rule named EC2InstanceStateChanges:
aws events delete-rule --name "EC2InstanceStateChanges"
- Java
-
- SDK for Java 2.x
-
public static void deleteRuleByName(EventBridgeClient eventBrClient, String ruleName) {
DeleteRuleRequest ruleRequest = DeleteRuleRequest.builder()
.name(ruleName)
.build();
eventBrClient.deleteRule(ruleRequest);
System.out.println("Successfully deleted the rule");
}
- Kotlin
-
- SDK for Kotlin
-
suspend fun deleteRuleByName(ruleName: String?) {
val ruleRequest = DeleteRuleRequest {
name = ruleName
}
EventBridgeClient { region = "us-east-1" }.use { eventBrClient ->
eventBrClient.deleteRule(ruleRequest)
println("Successfully deleted the rule")
}
}
For a complete list of Amazon SDK developer guides and code examples, see
Using EventBridge with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.