There are more AWS SDK examples available in the AWS Doc SDK Examples
Use ListRules
with an AWS SDK or CLI
The following code examples show how to use ListRules
.
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
-
- AWS SDK for .NET
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. List all of the rules for an event bus.
/// <summary> /// List the rules on an event bus. /// </summary> /// <param name="eventBusArn">The optional ARN of the event bus. If empty, uses the default event bus.</param> /// <returns>The list of rules.</returns> public async Task<List<Rule>> ListAllRulesForEventBus(string? eventBusArn = null) { var results = new List<Rule>(); var request = new ListRulesRequest() { EventBusName = eventBusArn }; // Get all of the pages of rules. ListRulesResponse response; do { response = await _amazonEventBridge.ListRulesAsync(request); results.AddRange(response.Rules); request.NextToken = response.NextToken; } while (response.NextToken is not null); return results; }
-
For API details, see ListRules in AWS SDK for .NET API Reference.
-
- CLI
-
- AWS CLI
-
To display a list of all CloudWatch Events rules
This example displays all CloudWatch Events rules in the region:
aws events list-rules
To display a list of CloudWatch Events rules beginning with a certain string.
This example displays all CloudWatch Events rules in the region that have a name starting with "Daily":
aws events list-rules --name-prefix
"Daily"
-
For API details, see ListRules
in AWS 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 AWS Code Examples Repository
. Enable a rule by using its rule name.
public static void listRules(EventBridgeClient eventBrClient) { try { ListRulesRequest rulesRequest = ListRulesRequest.builder() .eventBusName("default") .limit(10) .build(); ListRulesResponse response = eventBrClient.listRules(rulesRequest); List<Rule> rules = response.rules(); for (Rule rule : rules) { System.out.println("The rule name is : " + rule.name()); System.out.println("The rule description is : " + rule.description()); System.out.println("The rule state is : " + rule.stateAsString()); } } catch (EventBridgeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
-
For API details, see ListRules in AWS 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 AWS Code Examples Repository
. suspend fun listRules() { val rulesRequest = ListRulesRequest { eventBusName = "default" limit = 10 } EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> val response = eventBrClient.listRules(rulesRequest) response.rules?.forEach { rule -> println("The rule name is ${rule.name}") println("The rule ARN is ${rule.arn}") } } }
-
For API details, see ListRules
in AWS SDK for Kotlin API reference.
-