Search code examples
amazon-ecsamazon-vpcaws-fargate

Execute AWS ECS run-task with network configuration overrides


I'm running a task in AWS ECS using the CLI command run-task.

I'm successfully running a task as follows:

aws ecs run-task --cluster ${stackName}-cluster \
                 --task-definition ${stackName}-${tag} \
                 --launch-type="FARGATE" \
                 --network-configuration '{ "awsvpcConfiguration": { "assignPublicIp":"DISABLED", "securityGroups": ["sg-......"], "subnets": ["subnet-.....","subnet-.....","subnet-......"]}}' \
                 --count 1 \
                 --profile ${profile} \
                 --overrides file://overrides.json

They way I understand it, if you're using FARGATE you must to have NetworkMode: awsvpc in your TaskDefinition, and you need to specify the awsvpcConfiguration every time you run a task. This is all fine.

However, to make the above invocation tidier, is there a way to pass the --networkConfiguration above as an override. The documentation says you can pass environment variables, but it's not clear if this includes network.

I would be very grateful to anybody who could shed some light on this.


Solution

  • No you can't do that. Here's the full list of things you can specify in ECS Task Overrides. Network configuration is not in that list.

    The documentation says you can pass environment variables, but it's not clear if this includes network.

    The network configuration is not an environment variable.


    If you just want to be able to simplify the the command line by passing in more arguments from a file, you can use the --cli-input-json or --cli-input-yaml arguments.