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

aws_ecs: TaskDefinition constraint.type 'distinctInstance' is not supported #25905

Closed
IllarionovDimitri opened this issue Jun 8, 2023 · 4 comments · Fixed by #26384
Closed
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. documentation This is a problem with documentation. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@IllarionovDimitri
Copy link

IllarionovDimitri commented Jun 8, 2023

Describe the bug

According to the documentation ecs.Ec2Taskdefinition supports placement_constraints attribute (which looks kinda redundant, because ecs.Ec2Service supports both placement_constraints and placement_strategies)

ecs.Ec2TaskDefinition(
  self,
  id",
  family="ecs-family",
  task_role=task_role,
  placement_constraints=[ecs.PlacementConstraint.distinct_instances()],
)

Stack deployment raises following exception

Resource handler returned message: "Invalid request provided: Create TaskDefinition: constraint.type 'distinctInstance' is not supported. (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: 71214110-96ed-4631-a83e-74a3
8206a8db; Proxy: null)" (RequestToken: 59dedc0b-cb70-0b09-c0f5-9b580c5fe3da, HandlerErrorCode: InvalidRequest)

Expected Behavior

Either the ecs.Ec2Taskdefinition can be properly deployed with set placement_constraints attribute or it can be only defined in ecs.Ec2Service (regarding redundancy I am no quite sure, probably there are cases where definition of placement_constraints in ecs.Ec2Taskdefinition also makes sense)

Current Behavior

Error during stack deployment if placement_constraints is defined in ecs.Ec2Taskdefinition

Reproduction Steps

Define placement_constraints as follows in ecs.Ec2Taskdefinition and deploy the esc stack ()there is no error with cdk synth or cdk ls)

ecs.Ec2TaskDefinition(
  self,
  id",
  family="ecs-family",
  task_role=task_role,
  placement_constraints=[ecs.PlacementConstraint.distinct_instances()],
)

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.83.0

Framework Version

No response

Node.js Version

18

OS

Ubuntu 20.04.5 LTS

Language

Python

Language Version

3.10.6

Other information

No response

@IllarionovDimitri IllarionovDimitri added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 8, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Jun 8, 2023
@peterwoodworth
Copy link
Contributor

It looks like we should clarify this in the docs. You can specify distinctInstances when creating a Service, or running a task. You can specify memberOf when doing the previous two actions, or when creating a task or new revision. See the docs here

In CloudFormation this is reflected in being only able to specify memberOf for TaskDefinition, and being able to specify both for Service. This is also reflected in the API model as having different types for TaskDefinitionPlacementConstraint and PlacementConstraint.

@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort documentation This is a problem with documentation. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 8, 2023
@IllarionovDimitri
Copy link
Author

IllarionovDimitri commented Jun 8, 2023

understood.

at least in docs for Python CDK both Ec2Service and Ec2TaskDefinition implement the placement_constraints as (Optional[Sequence[[PlacementConstraint]]), so there is no TaskDefinitionPlacementConstraint, only the PlacementConstrain, which implements both distinct_instances() and member_of() class methods

@peterwoodworth
Copy link
Contributor

Sorry I wasn't clear, we don't separate these in our API, I was describing how they are separated in both CloudFormation and the actual ECS API. I don't think we need to separate these on our end, but we should put in the docstring and make a check at synth time that there are some invalid configurations.

@peterwoodworth peterwoodworth added the good first issue Related to contributions. See CONTRIBUTING.md label Jun 8, 2023
Adibuer-lab added a commit to Adibuer-lab/aws-cdk that referenced this issue Jun 11, 2023
@mergify mergify bot closed this as completed in #26384 Aug 2, 2023
mergify bot pushed a commit that referenced this issue Aug 2, 2023
…ints and no validation of input #25933 (#26384)

Docs were unclear on valid placement constraints. You can specify distinctInstances when creating a Service, or running a task. You can specify memberOf when doing the previous two actions, or when creating a task or new revision. So far only memberOf is valid for ec2 task definitions.

This pull request enhances the documentation and validation for task definition placement constraints in the aws-cdk-lib/aws-ecs package. The documentation now includes a note clarifying the valid placement constraints and a new validatePlacementConstraints method has been added to the Ec2TaskDefinition class to validate the constraints at synth time.

The changes include:

Enhancement of documentation in ec2-task-definition.ts to include a note about valid placement constraints.
Addition of the validatePlacementConstraints method in ec2-task-definition.ts to validate placement constraints at synth time.
Addition of unit tests in ec2-task-definition.test.ts to verify the correct behavior of the new validatePlacementConstraints method.
Addition of integration tests to ensure overall functionality.
Closes #25905.

Revival of #25933

----

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. documentation This is a problem with documentation. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
2 participants