Skip to content

Instantly share code, notes, and snippets.

@mlf4aiur
Created February 7, 2017 03:25
Show Gist options
  • Select an option

  • Save mlf4aiur/83833e9905bfb5779fc0a3035bca85c5 to your computer and use it in GitHub Desktop.

Select an option

Save mlf4aiur/83833e9905bfb5779fc0a3035bca85c5 to your computer and use it in GitHub Desktop.
function stop_ecs_service_tasks () {
local cluster_name=$1
local service_name=$2
local wait_time=${3:-10}
local tasks
local task
# Get tasks
tasks=$(aws --output json \
ecs list-tasks \
--cluster "${cluster_name}" \
--service-name "${service_name}" | \
jq '.taskArns[]' | sed 's@.*task/@@' | tr -d '"' | tr "\n" " ")
# Stop tasks
for task in ${tasks}; do
echo "Stoping task: ${cluster_name} ${service_name} ${task}"
aws ecs stop-task --task "${task}" --cluster "${cluster_name}"
sleep "${wait_time}"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment