Skip to content

Instantly share code, notes, and snippets.

@bwhaley
Created December 4, 2019 06:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwhaley/7383803e1dec6bff2ea05d8af634d5cb to your computer and use it in GitHub Desktop.
Save bwhaley/7383803e1dec6bff2ea05d8af634d5cb to your computer and use it in GitHub Desktop.
rolling deployment method
"""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