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 CLI
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
-
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;
}
- 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"
- Java
-
- SDK for Java 2.x
-
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);
}
}
- Kotlin
-
- SDK for Kotlin
-
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 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.