Infra & Cloud bash Intermediate New

ECS Task Force Stop

Force-stop all running ECS tasks in a service for emergency rollback.

bash
#!/bin/bash
CLUSTER=$1
SERVICE=$2

TASKS=$(aws ecs list-tasks --cluster $CLUSTER --service-name $SERVICE \
  --query "taskArns[]" --output text)

for task in $TASKS; do
  aws ecs stop-task --cluster $CLUSTER --task $task --reason "Emergency stop" > /dev/null
  echo "Stopped: $task"
done

echo "All tasks stopped. ECS will restart from the current task definition."

Prerequisites

  • aws-cli v2
  • ECS permissions

Pro Tips

  • → Pair with aws ecs update-service --desired-count 0 to prevent restart.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
bash
Level
Intermediate
Read time
3 min
Published
Sep 2026
License
Commercial License

Newsletter

New modules every week, directly to your inbox.