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 ListRuleNamesByTarget
with an Amazon SDK or command line tool
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
-
- Amazon SDK for .NET
-
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
-
- Amazon 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
-
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
-
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")
}
}
}
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.