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

The following code examples show how to use DescribeRule.

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.

Get the state of a rule using the rule description.

/// <summary> /// Get the state for a rule by the rule name. /// </summary> /// <param name="ruleName">The name of the rule.</param> /// <param name="eventBusName">The optional name of the event bus. If empty, uses the default event bus.</param> /// <returns>The state of the rule.</returns> public async Task<RuleState> GetRuleStateByRuleName(string ruleName, string? eventBusName = null) { var ruleResponse = await _amazonEventBridge.DescribeRuleAsync( new DescribeRuleRequest() { Name = ruleName, EventBusName = eventBusName }); return ruleResponse.State; }
  • For API details, see DescribeRule in Amazon SDK for .NET API Reference.

CLI
Amazon CLI

To display information about a CloudWatch Events rule

This example displays information about the rule named DailyLambdaFunction:

aws events describe-rule --name "DailyLambdaFunction"
  • For API details, see DescribeRule 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.

public static void checkRule(EventBridgeClient eventBrClient, String eventRuleName) { try { DescribeRuleRequest ruleRequest = DescribeRuleRequest.builder() .name(eventRuleName) .build(); DescribeRuleResponse response = eventBrClient.describeRule(ruleRequest); System.out.println("The state of the rule is " + response.stateAsString()); } catch (EventBridgeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • For API details, see DescribeRule 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 checkRule(eventRuleName: String?) { val ruleRequest = DescribeRuleRequest { name = eventRuleName } EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> val response = eventBrClient.describeRule(ruleRequest) println("The state of the rule is $response") } }
  • For API details, see DescribeRule 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.