Skip to content

Instantly share code, notes, and snippets.

@jkielbaey
Created November 25, 2018 20:04
Show Gist options
  • Save jkielbaey/e251ca38c11187eba1a107dd40969dc0 to your computer and use it in GitHub Desktop.
Save jkielbaey/e251ca38c11187eba1a107dd40969dc0 to your computer and use it in GitHub Desktop.
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