Run an AWS ECS Task From the Command Line

To run a one-off ECS task from the aws CLI in Fargate you need to specify the subnet, set assignPublicIp to enabled (otherwise it will fail to pull the container image), and optionally include overrides to run the command you want.

Example:

aws ecs run-task\
--cluster foo\
--task-definition bar\
--count 1\
--launch-type FARGATE\
--network-configuration '{"awsvpcConfiguration": {"subnets": ["subnet-123456"], "assignPublicIp": "ENABLED"}}'\
--overrides '{"containerOverrides": [{"name" : "MyTask", "command" : ["python", "example.py", "arg1_here"]}]}'