Created
December 4, 2019 06:34
-
-
Save bwhaley/7383803e1dec6bff2ea05d8af634d5cb to your computer and use it in GitHub Desktop.
rolling deployment method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Put ECS Instances in DRAINING state so that all ECS Tasks running on them are migrated to other Instances. | |
Batches into chunks of 10 because of AWS api limitations (An error occurred InvalidParameterException when | |
calling the UpdateContainerInstancesState operation: instanceIds can have at most 10 items) | |
""" | |
def put_container_instances_in_draining_state(ecs_client, cluster_name, container_instance_arns): | |
batch_size = 10 | |
n_batches = math.ceil(len(container_instance_arns)/batch_size) | |
for i in range(0, len(container_instance_arns), batch_size): | |
logger.info('Putting batch %d/%d of container instances %s in cluster %s into DRAINING state', i+1, n_batches, container_instance_arns, cluster_name) | |
ecs_client.update_container_instances_state(cluster=cluster_name, containerInstances=container_instance_arns[i:i + batch_size], status='DRAINING') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment