Sometimes I just want to run an ECS task on demand, not wait for EventBridge or a service.
This is how I do it for classic EC2-based ECS clusters (not Fargate).
🧠 When to use this
- For ad-hoc maintenance jobs (like log cleanup or data processing)
- To manually trigger an ECS task that’s normally run by EventBridge
- When testing a new task definition before automating it
⚙️ Prerequisites
- ECS cluster already exists and is EC2-based
- A task definition (family or ARN)
- IAM permissions to run ECS tasks
Check the cluster type:
aws ecs describe-clusters --clusters cluster1
🚀 Run the task manually
Minimal command:
aws ecs run-task \
--cluster cluster1 \
--task-definition arn:aws:ecs:ap-southeast-2:111122223333:task-definition/my-task:134 \
--count 1 \
--launch-type EC2 \
--region ap-southeast-2
That immediately starts the task on one of your ECS container instances.
🧩 Check task status
List recent tasks:
aws ecs list-tasks --cluster cluster1
Describe a task:
aws ecs describe-tasks --cluster cluster1 --tasks <task-id>
Stop a running task:
aws ecs stop-task --cluster cluster1 --task <task-id>
📝 Notes
-
--launch-type EC2
ensures it runs on existing container instances -
--enable-execute-command
allows you to connect usingaws ecs execute-command
- No network configuration is required for EC2 launch type
- Task permissions and env vars come from the task definition
✅ Summary
Quick reminder for myself:
- Use
aws ecs run-task
for manual ECS jobs - Works well for debugging, testing, or one-off operations
- Keep it simple — no EventBridge required
Top comments (0)