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

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

Closed
1 task done
Mahoney opened this issue Aug 14, 2024 · 6 comments
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. effort/medium Medium work item – several days of effort management/tracking Issues that track a subject or multiple issues p0 potential-regression Marking this issue as a potential regression to be checked by team member

Comments

@Mahoney
Copy link

Mahoney commented Aug 14, 2024

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

@Mahoney Mahoney added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 14, 2024
@github-actions github-actions bot added potential-regression Marking this issue as a potential regression to be checked by team member @aws-cdk/aws-ecs Related to Amazon Elastic Container labels Aug 14, 2024
@pahud pahud added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Aug 14, 2024
@pahud pahud self-assigned this Aug 14, 2024
@pahud
Copy link
Contributor

pahud commented Aug 14, 2024

initial investigation

this works in 2.150.0 and 2.151.0 in CDK TypeScript. No regression.

    const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
    const task = new ecs.TaskDefinition(this, 'Task', {
      cpu: '4096',
      memoryMiB: '8192',
      compatibility: ecs.Compatibility.FARGATE,
    });
    task.addContainer('nginx', {
      image: ecs.ContainerImage.fromRegistry('nginx:latest')
    })
    new ecs.FargateService(this, 'Service', {
      cluster,
      taskDefinition: task,
    })

checking Java.

@pahud
Copy link
Contributor

pahud commented Aug 14, 2024

OK the value is from CfnParameter. Investigating again.

@pahud
Copy link
Contributor

pahud commented Aug 14, 2024

OK confirmed a regression

export class DummyStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const vpc = getDefaultVpc(this);

    const cpuParam = new CfnParameter(this, 'cpuParam', {
      type: 'String',
      default: '4096', 
    });

    const memoryParam = new CfnParameter(this, 'memoryParam', {
      type: 'String',
      default: '8192',
    })

    const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
    const task = new ecs.TaskDefinition(this, 'Task', {
      cpu: cpuParam.valueAsString,
      memoryMiB: memoryParam.valueAsString,
      compatibility: ecs.Compatibility.FARGATE,
    });
    task.addContainer('nginx', {
      image: ecs.ContainerImage.fromRegistry('nginx:latest')
    })
    new ecs.FargateService(this, 'Service', {
      cluster,
      taskDefinition: task,
    })
  }
}

This synthesizes in 2.150.0 but fails in 2.151.0

 % npx cdk synth
/Users/hunhsieh/repos/issue-triage/node_modules/aws-cdk-lib/core/lib/private/synthesis.js:3
  `);throw new Error(`Validation failed with the following errors:
           ^
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)

Subprocess exited with error 1

I guess the bug is from here but we need more investigation from the team.

https://github.com/mrlikl/aws-cdk/blob/b4f36b293052bd28700b1162ae438682f61f1442/packages/aws-cdk-lib/aws-ecs/lib/base/task-definition.ts#L913-L925

As this is confirmed a regression. I am making it a p0.

@pahud pahud added p0 and removed needs-triage This issue or PR still needs to be triaged. potential-regression Marking this issue as a potential regression to be checked by team member labels Aug 14, 2024
@pahud pahud removed their assignment Aug 14, 2024
@pahud pahud added effort/medium Medium work item – several days of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Aug 14, 2024
@xazhao
Copy link
Contributor

xazhao commented Aug 14, 2024

The error is from this PR: #30166.

It added the validation but doesn't allow token to pass through.

@xazhao xazhao changed the title services.ecs: TaskDefinition.Builder.cpu rejects CfnParameter#getValueAsString ❗ NOTICE(ecs): Error: Invalid CPU and memory combinations for FARGATE compatible task definition Aug 14, 2024
@scanlonp
Copy link
Contributor

Hey @Mahoney, thanks for reporting this to us. We will patch this shortly. If you have not already, you should be able to unblock yourself in the mean time by pinning to a previous working version - 1.150.0.

@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Aug 14, 2024
@xazhao xazhao added the management/tracking Issues that track a subject or multiple issues label Aug 14, 2024
@xazhao xazhao pinned this issue Aug 14, 2024
xazhao added a commit to xazhao/aws-cdk-notices that referenced this issue Aug 14, 2024
mergify bot pushed a commit to cdklabs/aws-cdk-notices that referenced this issue Aug 14, 2024
@xazhao xazhao closed this as completed Aug 28, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2024
@xazhao xazhao unpinned this issue Aug 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. effort/medium Medium work item – several days of effort management/tracking Issues that track a subject or multiple issues p0 potential-regression Marking this issue as a potential regression to be checked by team member
Projects
None yet
Development

No branches or pull requests

4 participants