Use ListRuleNamesByTarget with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use ListRuleNamesByTarget with an AWS SDK or CLI

The following code examples show how to use ListRuleNamesByTarget.

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 rule names using the target.

/// <summary> /// List names of all rules matching a target. /// </summary> /// <param name="targetArn">The ARN of the target.</param> /// <returns>The list of rule names.</returns> public async Task<List<string>> ListAllRuleNamesByTarget(string targetArn) { var results = new List<string>(); var request = new ListRuleNamesByTargetRequest() { TargetArn = targetArn }; ListRuleNamesByTargetResponse response; do { response = await _amazonEventBridge.ListRuleNamesByTargetAsync(request); results.AddRange(response.RuleNames); request.NextToken = response.NextToken; } while (response.NextToken is not null); return results; }
CLI
AWS CLI

To display all the rules that have a specified target

This example displays all rules that have the Lambda function named "MyFunctionName" as the target:

aws events list-rule-names-by-target --target-arn "arn:aws:lambda:us-east-1:123456789012:function:MyFunctionName"
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.

List all of the rule names by using the target.

public static void listTargetRules(EventBridgeClient eventBrClient, String topicArn) { ListRuleNamesByTargetRequest ruleNamesByTargetRequest = ListRuleNamesByTargetRequest.builder() .targetArn(topicArn) .build(); ListRuleNamesByTargetResponse response = eventBrClient.listRuleNamesByTarget(ruleNamesByTargetRequest); List<String> rules = response.ruleNames(); for (String rule : rules) { System.out.println("The rule name is " + rule); } }
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 listTargetRules(topicArnVal: String?) { val ruleNamesByTargetRequest = ListRuleNamesByTargetRequest { targetArn = topicArnVal } EventBridgeClient { region = "us-east-1" }.use { eventBrClient -> val response = eventBrClient.listRuleNamesByTarget(ruleNamesByTargetRequest) response.ruleNames?.forEach { rule -> println("The rule name is $rule") } } }