Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/stop-ecs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Stop All ECS Tasks

on:
workflow_dispatch:
inputs:
confirm:
description: 'Type "yes" to confirm stopping all tasks'
required: true
type: string

env:
AWS_REGION: ${{ vars.AWS_REGION || 'eu-central-1' }}
ECS_SERVICE: ${{ vars.ECS_SERVICE || 'dev-zebra' }}
ECS_CLUSTER: ${{ vars.ECS_CLUSTER || 'dev-zebra-cluster' }}

jobs:
stop-tasks:
name: Stop All ECS Tasks
runs-on: ubuntu-latest
environment: production
steps:
- name: Validate confirmation
if: ${{ github.event.inputs.confirm != 'yes' }}
run: |
echo "Confirmation not provided. Please type 'yes' to confirm."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please type yes?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message is not clear enough. Consider the context and where the message is being shown and provide a clearer message.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

exit 1

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Stop all running tasks
run: |
echo "Fetching running tasks for service: $ECS_SERVICE in cluster: $ECS_CLUSTER"

TASK_ARNS=$(aws ecs list-tasks \
--cluster $ECS_CLUSTER \
--service-name $ECS_SERVICE \
--query 'taskArns[]' \
--output text)

if [ -z "$TASK_ARNS" ]; then
echo "No running tasks found."
exit 0
fi

echo "Found tasks: $TASK_ARNS"

for TASK_ARN in $TASK_ARNS; do
echo "Stopping task: $TASK_ARN"
aws ecs stop-task \
--cluster $ECS_CLUSTER \
--task $TASK_ARN \
--reason "Manually stopped via GitHub Actions"
done

echo "All tasks have been stopped."

- name: Verify tasks stopped
run: |
echo "Waiting 30 seconds for tasks to stop..."
sleep 30

echo "Current task status:"
aws ecs describe-services \
--cluster $ECS_CLUSTER \
--services $ECS_SERVICE \
--query 'services[0].{RunningCount:runningCount,PendingCount:pendingCount,DesiredCount:desiredCount}' \
--output table