Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jkcdarunday opened this issue Jun 24, 2020 · 7 comments

Comments

@jkcdarunday
Copy link

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:

  • A service that can scale is already running using the same task definition so it should be correct and there shouldn't be an issue with having two tasks with the same configuration.
  • ecs run ... does not work with Fargate #61 might be related, however, that issue is with using Fargate. Mine uses EC2 with awsvpc instead.
@jkcdarunday
Copy link
Author

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
Copy link
Owner

fabfuel commented Jun 25, 2020

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:

  • --subnet
  • --securitygroup

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

Best
Fabian

@fabfuel fabfuel closed this as completed Jun 25, 2020
@jkcdarunday
Copy link
Author

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
Copy link
Author

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?

if launchtype == LAUNCH_TYPE_FARGATE:
if not subnets or not security_groups:
msg = 'At least one subnet (--subnet) and one security ' \
'group (--securitygroup) definition are required ' \
'for launch type FARGATE'
raise TaskPlacementError(msg)
network_configuration = {
"awsvpcConfiguration": {
"subnets": subnets,
"securityGroups": security_groups,
"assignPublicIp": "ENABLED" if public_ip else "DISABLED"
}
}
return self.boto.run_task(
cluster=cluster,
taskDefinition=task_definition,
count=count,
startedBy=started_by,
overrides=overrides,
launchType=launchtype,
networkConfiguration=network_configuration
)
return self.boto.run_task(
cluster=cluster,
taskDefinition=task_definition,
count=count,
startedBy=started_by,
overrides=overrides
)

@fabfuel
Copy link
Owner

fabfuel commented Jun 25, 2020

Indeed, you're right

@fabfuel fabfuel reopened this Jun 25, 2020
@jkcdarunday
Copy link
Author

jkcdarunday commented Jun 25, 2020

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 jkcdarunday@6e8ee0d

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
Copy link
Owner

fabfuel commented Jun 28, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants