本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DescribeRule
搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 DescribeRule
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- .NET
-
- AWS SDK for .NET
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 使用規則描述取得規則的狀態。
/// <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; }
-
如需 API 詳細資訊,請參閱《AWS SDK for .NET API 參考》中的 DescribeRule。
-
- CLI
-
- AWS CLI
-
顯示 CloudWatch Events 規則的相關資訊
此範例會顯示名為 DailyLambdaFunction 之規則的相關資訊:
aws events describe-rule --name
"DailyLambdaFunction"
-
如需 API 的詳細資訊,請參閱《AWS CLI 命令參考》中的 DescribeRule
。
-
- Java
-
- SDK for Java 2.x
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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); } }
-
如需 API 詳細資訊,請參閱《AWS SDK for Java 2.x API 參考》中的 DescribeRule。
-
- Kotlin
-
- SDK for Kotlin
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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") } }
-
如需 API 詳細資訊,請參閱《適用於 Kotlin 的AWS SDK API 參考》中的 DescribeRule
。
-
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 搭配 AWS SDK 使用 EventBridge 。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。
DeleteRule
DisableRule