AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭GetRoutingControlState
配 AWS SDK或使用 CLI
下列程式碼範例會示範如何使用GetRoutingControlState
。
- Java
-
- SDK對於爪哇 2.x
-
注意
還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 public static GetRoutingControlStateResponse getRoutingControlState(List<ClusterEndpoint> clusterEndpoints, String routingControlArn) { // As a best practice, we recommend choosing a random cluster endpoint to get or // set routing control states. // For more information, see // https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional Collections.shuffle(clusterEndpoints); for (ClusterEndpoint clusterEndpoint : clusterEndpoints) { try { System.out.println(clusterEndpoint); Route53RecoveryClusterClient client = Route53RecoveryClusterClient.builder() .endpointOverride(URI.create(clusterEndpoint.endpoint())) .region(Region.of(clusterEndpoint.region())).build(); return client.getRoutingControlState( GetRoutingControlStateRequest.builder() .routingControlArn(routingControlArn).build()); } catch (Exception exception) { System.out.println(exception); } } return null; }
-
如需詳API細資訊,請參閱AWS SDK for Java 2.x API參考GetRoutingControlState中的。
-
- Python
-
- SDK對於 Python(肉毒桿菌 3)
-
注意
還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 import boto3 def create_recovery_client(cluster_endpoint): """ Creates a Boto3 Route 53 Application Recovery Controller client for the specified cluster endpoint URL and AWS Region. :param cluster_endpoint: The cluster endpoint URL and Region. :return: The Boto3 client. """ return boto3.client( "route53-recovery-cluster", endpoint_url=cluster_endpoint["Endpoint"], region_name=cluster_endpoint["Region"], ) def get_routing_control_state(routing_control_arn, cluster_endpoints): """ Gets the state of a routing control. Cluster endpoints are tried in sequence until the first successful response is received. :param routing_control_arn: The ARN of the routing control to look up. :param cluster_endpoints: The list of cluster endpoints to query. :return: The routing control state response. """ # As a best practice, we recommend choosing a random cluster endpoint to get or set routing control states. # For more information, see https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional random.shuffle(cluster_endpoints) for cluster_endpoint in cluster_endpoints: try: recovery_client = create_recovery_client(cluster_endpoint) response = recovery_client.get_routing_control_state( RoutingControlArn=routing_control_arn ) return response except Exception as error: print(error) raise error
-
如需詳API細資訊,請參閱GetRoutingControlState中AWS SDK的〈〉以取得 Python (Boto3) API 參考資料。
-
動作
UpdateRoutingControlState