Skip to content

Commit eaf86ad

Browse files
ccmolik-awsChris Cmolik
andauthored
Update routing control state examples to recommend accessing a random… (#4404)
* Update routing control state examples to recommend accessing a random endpoint * Update routing control state recommendation wording --------- Co-authored-by: Chris Cmolik <[email protected]>
1 parent 78e49e1 commit eaf86ad

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

javav2/example_code/route53recoverycluster/src/main/java/com/example/route53recoverycluster/GetRoutingControlState.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.net.URI;
1818
import java.util.ArrayList;
1919
import java.util.Arrays;
20+
import java.util.Collections;
2021
import java.util.List;
2122
import java.util.stream.Collectors;
2223
//snippet-end:[route53_rec.java2.get_routing.import]
@@ -67,6 +68,9 @@ private static List<ClusterEndpoint> getClusterEndpoints(final String endpointsF
6768
//snippet-start:[route53_rec.java2.get_routing.main]
6869
public static GetRoutingControlStateResponse getRoutingControlState(List<ClusterEndpoint> clusterEndpoints,
6970
String routingControlArn) {
71+
// As a best practice, we recommend choosing a random cluster endpoint to get or set routing control states.
72+
// For more information, see https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional
73+
Collections.shuffle(clusterEndpoints);
7074
for (ClusterEndpoint clusterEndpoint : clusterEndpoints) {
7175
try {
7276
System.out.println(clusterEndpoint);

javav2/example_code/route53recoverycluster/src/main/java/com/example/route53recoverycluster/UpdateRoutingControlState.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.net.URI;
1818
import java.util.ArrayList;
1919
import java.util.Arrays;
20+
import java.util.Collections;
2021
import java.util.List;
2122
import java.util.stream.Collectors;
2223
//snippet-end:[route53_rec.java2.update_routing_state.import]
@@ -71,6 +72,9 @@ private static List<ClusterEndpoint> getClusterEndpoints(final String endpointsF
7172
public static UpdateRoutingControlStateResponse updateRoutingControlState(List<ClusterEndpoint> clusterEndpoints,
7273
String routingControlArn,
7374
String routingControlState) {
75+
// As a best practice, we recommend choosing a random cluster endpoint to get or set routing control states.
76+
// For more information, see https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional
77+
Collections.shuffle(clusterEndpoints);
7478
for (ClusterEndpoint clusterEndpoint : clusterEndpoints) {
7579
try {
7680
System.out.println(clusterEndpoint);

python/example_code/route53-recovery-cluster/routing_control_states.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import argparse
1212
import json
13+
import random
1314

1415
# snippet-start:[python.example_code.route53-recovery-cluster.helper.get_recovery_client]
1516
import boto3
@@ -40,6 +41,10 @@ def get_routing_control_state(routing_control_arn, cluster_endpoints):
4041
:param cluster_endpoints: The list of cluster endpoints to query.
4142
:return: The routing control state response.
4243
"""
44+
45+
# As a best practice, we recommend choosing a random cluster endpoint to get or set routing control states.
46+
# For more information, see https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional
47+
random.shuffle(cluster_endpoints)
4348
for cluster_endpoint in cluster_endpoints:
4449
try:
4550
recovery_client = create_recovery_client(cluster_endpoint)
@@ -48,6 +53,7 @@ def get_routing_control_state(routing_control_arn, cluster_endpoints):
4853
return response
4954
except Exception as error:
5055
print(error)
56+
raise error
5157
# snippet-end:[python.example_code.route53-recovery-cluster.GetRoutingControlState]
5258

5359

@@ -63,6 +69,10 @@ def update_routing_control_state(
6369
:param routing_control_state: The new routing control state.
6470
:return: The routing control update response.
6571
"""
72+
73+
# As a best practice, we recommend choosing a random cluster endpoint to get or set routing control states.
74+
# For more information, see https://docs.aws.amazon.com/r53recovery/latest/dg/route53-arc-best-practices.html#route53-arc-best-practices.regional
75+
random.shuffle(cluster_endpoints)
6676
for cluster_endpoint in cluster_endpoints:
6777
try:
6878
recovery_client = create_recovery_client(cluster_endpoint)
@@ -105,5 +115,5 @@ def toggle_routing_control_state(routing_control_arn, cluster_endpoints):
105115
'cluster_endpoints', help="A JSON file containing the list of endpoints for the cluster.")
106116
args = parser.parse_args()
107117
with open(args.cluster_endpoints) as endpoints_file:
108-
cluster_endpoints = json.load(endpoints_file)['ClusterEndpoints']
109-
toggle_routing_control_state(args.routing_control_arn, cluster_endpoints)
118+
loaded_cluster_endpoints = json.load(endpoints_file)['ClusterEndpoints']
119+
toggle_routing_control_state(args.routing_control_arn, loaded_cluster_endpoints)

0 commit comments

Comments
 (0)