Run ad-hoc containers on ECS.
This does not aim to replace the offical AWS ECS CLI, but complement it. The official CLI doesn't support docker run
like commands.
This CLI is designed to closely resemble the docker run
command for ECS. This will allow users to run any container against a cluster without previously having to define a task definition. It will provision the necessary AWS resources like the task definition and CloudWatch log group, start your container, and stream the logs back to stdout.
- replicate
docker run
arguments - provision the necessary AWS resources to run a container
- allow custom task-definition name
- the exit code from the container is mirrored by the CLI
- capture a SIGKILL event (Ctrl+c) and stop the remote container
- replicate
docker exec
arguments using SSM agent
Download the latest release for your OS and extract to your PATH.
➜ ~ ecs run --cluster ops bash ping -c 5 google.com
Creating task definition
Running task definition: arn:aws:ecs:us-east-1:000000000000:task-definition/ephemeral-task-from-ecs-cli:1
Streaming from Cloudwatch Logs
https://console.aws.amazon.com/ecs/home?#/clusters/ops/tasks/00000000000000000000000000000000/details
Container is starting on EC2 instance i-00000000000000000 (10.100.1.25).
2019-01-19 20:25:08 -0600 CST PING google.com (172.217.7.238): 56 data bytes
2019-01-19 20:25:08 -0600 CST 64 bytes from 172.217.7.238: seq=0 ttl=46 time=2.020 ms
2019-01-19 20:25:09 -0600 CST 64 bytes from 172.217.7.238: seq=1 ttl=46 time=1.303 ms
2019-01-19 20:25:10 -0600 CST 64 bytes from 172.217.7.238: seq=2 ttl=46 time=1.263 ms
2019-01-19 20:25:11 -0600 CST 64 bytes from 172.217.7.238: seq=3 ttl=46 time=1.230 ms
2019-01-19 20:25:12 -0600 CST 64 bytes from 172.217.7.238: seq=4 ttl=46 time=1.313 ms
2019-01-19 20:25:12 -0600 CST --- google.com ping statistics ---
2019-01-19 20:25:12 -0600 CST 5 packets transmitted, 5 packets received, 0% packet loss
2019-01-19 20:25:12 -0600 CST round-trip min/avg/max = 1.230/1.425/2.020 ms
Task arn:aws:ecs:us-east-1:000000000000:task/ops/00000000000000000000000000000000 has stopped (exit code 0):
Essential container in task exited
All containers have exited
Usage:
ecs run [flags]
Flags:
--cluster string ECS cluster
-c, --count int Spawn n tasks (default 1)
--cpu-reservation int CPU reservation (default 1024)
-d, --detach Run the task in the background
-e, --env stringArray Set environment variables
--execution-role string Execution role ARN (required for Fargate)
--fargate Launch in Fargate
-h, --help help for run
-m, --memory int Memory limit
--memory-reservation int Memory reservation (default 2048)
-n, --name string Assign a name to the task (default "ecs-cli-app")
-p, --publish stringArray Publish a container's port(s) to the host
--subnet stringArray Subnet(s) where task should run
-v, --volume stringArray Map volume to ECS Container Instance