Describe the bug
When I add a container definition to a fargate task definition, I am prompted to include memory or memoryReservation as a required field. This is not a container-level requirement if memory is already specified in the task.
Expected Behavior
I expect the CDK to let me create a container without specifying memory.
Current Behavior
Error: Validation failed with the following errors:
[EcsWorkspaceStack/nginxTaskDef] ECS Container web must have at least one of 'memoryLimitMiB' or 'memoryReservationMiB' specified
at validateTree (/Users/petderek/experiments/ecs-workspace/node_modules/aws-cdk-lib/core/lib/private/synthesis.ts:356:11)
at synthesize (/Users/petderek/experiments/ecs-workspace/node_modules/aws-cdk-lib/core/lib/private/synthesis.ts:49:5)
at App.synth (/Users/petderek/experiments/ecs-workspace/node_modules/aws-cdk-lib/core/lib/stage.ts:217:33)
at process.<anonymous> (/Users/petderek/experiments/ecs-workspace/node_modules/aws-cdk-lib/core/lib/app.ts:195:45)
Reproduction Steps
Something like this should repro:
const basicNginxTask = new aws_ecs.TaskDefinition(this, "nginxTaskDef", {
compatibility: aws_ecs.Compatibility.EC2_AND_FARGATE,
cpu: "256",
executionRole: task_execution_role,
family: "nginx",
memoryMiB: "512",
networkMode: aws_ecs.NetworkMode.AWS_VPC,
});
basicNginxTask.addContainer("nginxContainer", {
containerName: "web",
essential: true,
image: aws_ecs.ContainerImage.fromRegistry("public.ecr.aws/nginx/nginx:stable"),
portMappings: [{containerPort: 80}],
// uncomment this to 'fix' and compile
//memoryReservationMiB: 512,
});
Possible Solution
One solution would be to check if there is memory set at in the parent before validating the existence of memory in the container.
Additional Information/Context
The correct behavior is mentioned in the register-task-definition documentation.
If using the Fargate launch type, this parameter is optional.
If using the EC2 launch type, you must specify either a task-level memory value or a container-level memory value. If you specify both a container-level memory and memoryReservation value, memory must be greater than memoryReservation . If you specify memoryReservation , then that value is subtracted from the available memory resources for the container instance where the container is placed. Otherwise, the value of memory is used.
CDK CLI Version
2.76.0 (build 78c411b)
Framework Version
No response
Node.js Version
v18.16.0
OS
mac
Language
Typescript
Language Version
No response
Other information
No response
Describe the bug
When I add a container definition to a fargate task definition, I am prompted to include
memoryormemoryReservationas a required field. This is not a container-level requirement if memory is already specified in the task.Expected Behavior
I expect the CDK to let me create a container without specifying
memory.Current Behavior
Reproduction Steps
Something like this should repro:
Possible Solution
One solution would be to check if there is
memoryset at in the parent before validating the existence ofmemoryin the container.Additional Information/Context
The correct behavior is mentioned in the
register-task-definitiondocumentation.CDK CLI Version
2.76.0 (build 78c411b)
Framework Version
No response
Node.js Version
v18.16.0
OS
mac
Language
Typescript
Language Version
No response
Other information
No response