Use UpdateRoutingControlState with an Amazon SDK or CLI - Amazon Route 53 Application Recovery Controller
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 UpdateRoutingControlState with an Amazon SDK or CLI

The following code examples show how to use UpdateRoutingControlState.

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 Amazon Code Examples Repository.

public static UpdateRoutingControlStateResponse updateRoutingControlState(List<ClusterEndpoint> clusterEndpoints, String routingControlArn, String routingControlState) { // 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.updateRoutingControlState( UpdateRoutingControlStateRequest.builder() .routingControlArn(routingControlArn).routingControlState(routingControlState).build()); } catch (Exception exception) { System.out.println(exception); } } return null; }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

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 update_routing_control_state( routing_control_arn, cluster_endpoints, routing_control_state ): """ Updates 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 update the state for. :param cluster_endpoints: The list of cluster endpoints to try. :param routing_control_state: The new routing control state. :return: The routing control update 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.update_routing_control_state( RoutingControlArn=routing_control_arn, RoutingControlState=routing_control_state, ) return response except Exception as error: print(error)

For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.