-
-
Save filipeandre/29f03ac7e01026f53ec3d51bc204519a to your computer and use it in GitHub Desktop.
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
import boto3 | |
ecs = boto3.client('ecs') | |
ssm = boto3.client('ssm') | |
cluster_name = “sample-cluster” | |
service_name = “sample-service” | |
# To stop the tasks | |
response = ecs.describe_services( | |
cluster=cluster_name, | |
services=[service_name] | |
) | |
nr_tasks = response[‘services’][0][‘desiredCount’] | |
ssm.put_parameter( | |
Name=’/ecs/{}/{}/desired_count’.format( | |
cluster_name, | |
service_name), | |
Value=str(nr_tasks), | |
Type='String', | |
Overwrite=True, | |
) | |
response = ecs.update_service( | |
cluster=cluster_name, | |
service=service_name, | |
desiredCount=0) | |
# To start the tasks again | |
response = ssm.get_parameter( | |
Name=’/ecs/{}/{}/desired_count’.format( | |
cluster_name, | |
service_name) | |
) | |
nr_tasks = response[‘Parameter’][‘Value’] | |
response = client.update_service( | |
cluster=cluster_name, | |
service=service_name, | |
desiredCount=nr_tasks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment