Skip to content

❗ NOTICE(ecs): Error: Invalid CPU and memory combinations for FARGATE compatible task definitionΒ #31106

@Mahoney

Description

@Mahoney

Please add your +1 πŸ‘ to let us know you have encountered this

Status:

Fixed in versions after 2.151.1

Overview:

A validation was added to check if the memory/cpu combination is FARGATE compatible task definition for ECS in this PR: #30166.
However the validation doesn't allow token to pass through so it will fail the synthesize.
This issue was introduced in CDK version 2.151.0

Complete Error Message:

Error: Validation failed with the following errors:
  [dummy-stack7/Task] Invalid CPU and memory combinations for FARGATE compatible task definition - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
    at validateTree (/Users/hunhsieh/repos/issue-triage/node_modules/aws-cdk-lib/core/lib/private/synthesis.js:3:12)
    at synthesize (/Users/hunhsieh/repos/issue-triage/node_modules/aws-cdk-lib/core/lib/private/synthesis.js:1:1561)
    at App.synth (/Users/hunhsieh/repos/issue-triage/node_modules/aws-cdk-lib/core/lib/stage.js:1:2263)
    at process.<anonymous> (/Users/hunhsieh/repos/issue-triage/node_modules/aws-cdk-lib/core/lib/app.js:1:1745)
    at Object.onceWrapper (node:events:628:26)
    at process.emit (node:events:513:28)
    at process.emit (node:domain:489:12)
    at process.emit.sharedData.processEmitHook.installedValue [as emit] (/Users/hunhsieh/repos/issue-triage/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)

Workaround:

Pinning CDK version to 2.150 or before. This issue only exists in the latest CDK version 2.151

Solution:

Will revert the change and do a patch release.


Original Issue Content:

Describe the bug

In 1.150.0 we were able to define a Service Catalog product which launched an ECS Service as so:

var cpu = CfnParameter.Builder
  .create(this, "cpu")
  .type("String")
  .description("The number of cpu units used by the task. 1024 == 1 vCPU.")
  .defaultValue("4096")
  .build();

var memoryMiB = CfnParameter.Builder
  .create(this, "memoryMiB")
  .type("String")
  .description("The amount (in MiB) of memory used by the task.")
  .defaultValue("8192")
  .build();

FargateService.Builder
  .create(this, "my-service")
  .taskDefinition(
    TaskDefinition.Builder.create(this, "my-task-def")
      .cpu(cpu.valueAsString)
      .memoryMiB(memoryMiB.valueAsString)
      .build()
  )
  .build();

On upgrading to 1.151.0 our tests fail as so:

java.lang.RuntimeException: Error: Validation failed with the following errors:
  [my-stack-dev/my-product/my-stack-dev/my-product-task-def] Invalid CPU and memory combinations for FARGATE compatible task definition - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
@jsii/kernel.RuntimeError: Error: Validation failed with the following errors:
  [wiremock-cloud-dev/mock-host-product/wiremock-cloud-dev-mock-host-task-def] Invalid CPU and memory combinations for FARGATE compatible task definition - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html
    at Kernel._Kernel_ensureSync (/private/var/folders/7w/gfcq0bbx36qbtjxcjy3f5xwh0000gn/T/jsii-java-runtime14482662822545602493/lib/program.js:9510:23)
    at Kernel.sinvoke (/private/var/folders/7w/gfcq0bbx36qbtjxcjy3f5xwh0000gn/T/jsii-java-runtime14482662822545602493/lib/program.js:8895:102)
    at KernelHost.processRequest (/private/var/folders/7w/gfcq0bbx36qbtjxcjy3f5xwh0000gn/T/jsii-java-runtime14482662822545602493/lib/program.js:10715:36)
    at KernelHost.run (/private/var/folders/7w/gfcq0bbx36qbtjxcjy3f5xwh0000gn/T/jsii-java-runtime14482662822545602493/lib/program.js:10675:22)
    at Immediate._onImmediate (/private/var/folders/7w/gfcq0bbx36qbtjxcjy3f5xwh0000gn/T/jsii-java-runtime14482662822545602493/lib/program.js:10676:46)
    at process.processImmediate (node:internal/timers:476:21)
	at software.amazon.jsii.JsiiRuntime.processErrorResponse(JsiiRuntime.java:147)
	at software.amazon.jsii.JsiiRuntime.requestResponse(JsiiRuntime.java:116)
	at software.amazon.jsii.JsiiClient.callStaticMethod(JsiiClient.java:168)
	at software.amazon.jsii.JsiiObject.jsiiStaticCall(JsiiObject.java:187)
	at software.amazon.jsii.JsiiObject.jsiiStaticCall(JsiiObject.java:166)
	at software.amazon.awscdk.assertions.Template.fromStack(Template.java:71)

If I replace cpu.valueAsString with the literal "4096" and memoryMiB.valueAsString with the literal "8192" it works, so it looks to me as if some validation is incorrectly failing to notice that these values are from parameters.

For clarity, we have successfully been creating provisioned products using this service catalog for a year or more using these CfnParameter s.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

1.150.0

Expected Behavior

Call to Template.fromStack should not throw an exception

Current Behavior

Call to Template.fromStack does throw an exception

Reproduction Steps

See code in description.

Possible Solution

No response

Additional Information/Context

We have successfully been creating provisioned products using this service catalog for a year or more using these CfnParameter s.

CDK CLI Version

1.151.0

Framework Version

No response

Node.js Version

v18.16.0

OS

macOs & Linux

Language

Java

Language Version

17

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ecsRelated to Amazon Elastic ContainerbugThis issue is a bug.effort/mediumMedium work item – several days of effortmanagement/trackingIssues that track a subject or multiple issuesp0potential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions