Delete an EventBridge rule using an Amazon SDK - Amazon EventBridge
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).

Delete an EventBridge rule using an Amazon SDK

The following code examples show how to delete an Amazon EventBridge rule.

.NET
Amazon SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

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; }
  • For API details, see DeleteRule in Amazon SDK for .NET API Reference.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

public static void deleteEBRule(EventBridgeClient eventBrClient, String ruleName) { try { DisableRuleRequest disableRuleRequest = DisableRuleRequest.builder() .name(ruleName) .eventBusName("default") .build(); eventBrClient.disableRule(disableRuleRequest); DeleteRuleRequest ruleRequest = DeleteRuleRequest.builder() .name(ruleName) .eventBusName("default") .build(); eventBrClient.deleteRule(ruleRequest); System.out.println("Rule "+ruleName + " was successfully deleted!"); } catch (EventBridgeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • For API details, see DeleteRule in Amazon SDK for Java 2.x API Reference.

Kotlin
SDK for Kotlin
Note

This is prerelease documentation for a feature in preview release. It is subject to change.

Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

suspend fun deleteEBRule(ruleName: String) { val request = DisableRuleRequest { name = ruleName eventBusName = "default" } EventBridgeClient { region = "us-west-2" }.use { eventBrClient -> eventBrClient.disableRule(request) val ruleRequest = DeleteRuleRequest { name = ruleName eventBusName = "default" } eventBrClient.deleteRule(ruleRequest) println("Rule $ruleName was successfully deleted!") } }
  • For API details, see DeleteRule in Amazon SDK for Kotlin API reference.

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.