Use DisableRule with an Amazon SDK or command line tool - 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).

Use DisableRule with an Amazon SDK or command line tool

The following code examples show how to use DisableRule.

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
Note

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

Disable a rule by its rule name.

/// <summary> /// Disable a particular rule on an event bus. /// </summary /// <param name="ruleName">The name of the rule.</param> /// <returns>True if successful.</returns> public async Task<bool> DisableRuleByName(string ruleName) { var ruleResponse = await _amazonEventBridge.DisableRuleAsync( new DisableRuleRequest() { Name = ruleName }); return ruleResponse.HttpStatusCode == HttpStatusCode.OK; }
  • For API details, see DisableRule in Amazon SDK for .NET API Reference.

CLI
Amazon CLI

To disable a CloudWatch Events rule

This example disables the rule named DailyLambdaFunction. The rule is not deleted:

aws events disable-rule --name "DailyLambdaFunction"
  • For API details, see DisableRule in Amazon CLI Command 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.

Disable a rule by using its rule name.

public static void changeRuleState(EventBridgeClient eventBrClient, String eventRuleName, Boolean isEnabled) { try { if (!isEnabled) { System.out.println("Disabling the rule: " + eventRuleName); DisableRuleRequest ruleRequest = DisableRuleRequest.builder() .name(eventRuleName) .build(); eventBrClient.disableRule(ruleRequest); } else { System.out.println("Enabling the rule: " + eventRuleName); EnableRuleRequest ruleRequest = EnableRuleRequest.builder() .name(eventRuleName) .build(); eventBrClient.enableRule(ruleRequest); } } catch (EventBridgeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • For API details, see DisableRule in Amazon SDK for Java 2.x API Reference.

Kotlin
SDK for Kotlin
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 changeRuleState(eventRuleName: String, isEnabled: Boolean?) { if (!isEnabled!!) { println("Disabling the rule: $eventRuleName") val ruleRequest = DisableRuleRequest { name = eventRuleName } EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> eventBrClient.disableRule(ruleRequest) } } else { println("Enabling the rule: $eventRuleName") val ruleRequest = EnableRuleRequest { name = eventRuleName } EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> eventBrClient.enableRule(ruleRequest) } } }
  • For API details, see DisableRule 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.