fabfuel / ecs-deploy

Powerful CLI tool to simplify Amazon ECS deployments, rollbacks & scaling
Other
854 stars 148 forks source link

ecs run: InvalidParameterException thrown when running a task definition using awsvpc + EC2 launch type #133

Open jkcdarunday opened 4 years ago

jkcdarunday commented 4 years ago

Hi,

I get the following when I try to use the run command on a task that use the EC2 launch type and awsvpc as the network mode:

% ecs run staging projects -c projects "npm run initdb"                                                                                                                                                                                                                      
Using task definition: projects
Changed command of container "projects" to: "npm run initdb" (was: "[]")

An error occurred (InvalidParameterException) when calling the RunTask operation: Network Configuration must be provided when networkMode 'awsvpc' is specified.

Notes:

jkcdarunday commented 4 years ago

Tried to do this in the AWS web interface. It seems that VPC, security group, and subnet are required even though I'm running with EC2.

Screenshot_20200625_064118

I was able to successfully run a task with a command override using the web interface.

fabfuel commented 4 years ago

Hi @jkcdarunday,

when running a task in network mode "awsvpc", you have to provide the subnet and the security group - like you do in the web (in your screenshot). You can provide those in the call with:

All details and options you can see via ecs run --help.

Best Fabian

jkcdarunday commented 4 years ago

Hi @fabfuel I have tried that as well. However, it did not seem to work and threw the same error.

% ecs run staging projects -c projects "npm run initdb" --launch-type EC2  --securitygroup sg-xxxxxxxxx --subnet subnet-xxxxxxxxx                                                           
Using task definition: projects
Changed command of container "projects" to: "npm run initdb" (was: "[]")

An error occurred (InvalidParameterException) when calling the RunTask operation: Network Configuration must be provided when networkMode 'awsvpc' is specified.
jkcdarunday commented 4 years ago

Looking at the code, it seems that no networkConfiguration value is being passed if the launch type is EC2 (it is only added on Fargate).

Perhaps networkConfiguration should be passed for the EC2 launch type as well as EC2 also supports awsvpc? https://github.com/fabfuel/ecs-deploy/blob/fe7447af8afb36461bfd5605ed965d8ead514201/ecs_deploy/ecs.py#L93-L124

fabfuel commented 4 years ago

Indeed, you're right

jkcdarunday commented 4 years ago

I have tried to edit the code to always pass networkConfiguration regardless of launch type and it seems to be working with my fork's commit at https://github.com/jkcdarunday/ecs-deploy/commit/6e8ee0d4098858ec3f6618d66586c709bd5f792a

Should I do a pull request? I am not sure if specifying an awsvpcConfiguration affects task definitions that don't use awsvpc though as all of my services currently use awsvpc.

% python ecs_deploy/cli.py run staging projects -c projects "npm run initdb"  --securitygroup sg-xxxxxxxx --subnet subnet-xxxxxxxx
Using task definition: projects
Changed command of container "projects" to: "npm run initdb" (was: "[]")

Successfully started 1 instances of task: projects:4
- arn:aws:ecs:ap-southeast-1:xxxxxxxxx:task/staging/xxxxx
fabfuel commented 4 years ago

Thanks @jkcdarunday, I think the safes way is to add a new argument for the network mode and to require and add the network config to the task definition only, if it is set to awsvpc.

Best Fabian