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-cdk-lib: Fargate task check requires at least 21G of storage but docs say 20G is the mininum #31291

Closed
1 task
JoshMcCullough opened this issue Sep 2, 2024 · 8 comments
Assignees
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/small Small work item – less than a day of effort p3

Comments

@JoshMcCullough
Copy link

Describe the bug

When configuring a FargateTaskDefinition, passing ephemeralStorageGiB: 20 throws the following error, even though the docs suggest that 20G is the minimum allowed.

Ephemeral storage size must be between 21GiB and 200GiB

Regression Issue

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

Last Known Working CDK Version

No response

Expected Behavior

ephemeralStorageGiB: 20 should be allowed, or the docs should be updated.

Current Behavior

ephemeralStorageGiB: 20 is not allowed, minimum value must be 21.

Reproduction Steps

  1. Configure a FargateTaskDefinition.
  2. Set: ephemeralStorageGiB: 20
  3. Try to synth.

Possible Solution

Fix aws-cdk-lib/aws-ecs/lib/fargate/fargate-task-definition.js to check `(props.ephemeralStorageGiB<20||props.ephemeralStorageGiB>200), or fix the docs.

Additional Information/Context

No response

CDK CLI Version

2.155.0

Framework Version

No response

Node.js Version

18.19.0

OS

Manjaro Linux

Language

TypeScript

Language Version

5.5.4

Other information

No response

@JoshMcCullough JoshMcCullough added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 2, 2024
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Sep 2, 2024
@ashishdhingra ashishdhingra self-assigned this Sep 3, 2024
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 3, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Sep 3, 2024

@ashishdhingra ashishdhingra added effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Sep 3, 2024
@mazyu36
Copy link
Contributor

mazyu36 commented Sep 4, 2024

Hello.

I modified the if statement and attempted to deploy with 20GB, but I encountered the following error.
The current implementation seems correct.

スクリーンショット 2024-09-03 22 23 43

It is also noted in the Management Console.
image

@ashishdhingra
Copy link
Contributor

Hello.

I modified the if statement and attempted to deploy with 20GB, but I encountered the following error. The current implementation seems correct.

スクリーンショット 2024-09-03 22 23 43

It is also noted in the Management Console. image

@mazyu36 Good observation. I will revalidate and would probably open ticket with CloudFormation team for documentation correction.

@ashishdhingra
Copy link
Contributor

ashishdhingra commented Sep 6, 2024

Tried to bypass CDK validation using below code (uses escape hatch):

import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

import path = require('path');


export class CdktestStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // Create an ECS cluster
    const vpc = ec2.Vpc.fromLookup(this, 'MyDefaultVpc', {
      isDefault: true
    });
    const cluster = new ecs.Cluster(this, 'Cluster', { vpc });

    // Add capacity to it
    cluster.addCapacity('DefaultAutoScalingGroupCapacity', {
      instanceType: new ec2.InstanceType("t2.xlarge"),
      desiredCapacity: 3,
    });

    const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', { ephemeralStorageGiB: 21 });
    (taskDefinition.node.defaultChild as ecs.CfnTaskDefinition).addPropertyOverride('EphemeralStorage', 20);

    taskDefinition.addContainer('DefaultContainer', {
      image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
      memoryLimitMiB: 512,
    });

    // Instantiate an Amazon ECS Service
    const ecsService = new ecs.FargateService(this, 'FargateService', {
      cluster,
      taskDefinition,
    });
  }
}

Although it is able to set EphemeralStorage to 20 in CloudFormation template:

Resources:
  ...
  ...
  TaskDef54694570:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Essential: true
          Image: amazon/amazon-ecs-sample
          Memory: 512
          Name: DefaultContainer
      Cpu: "256"
      EphemeralStorage: 20
      Family: CdktestStackTaskDefB8572B74
      Memory: "512"
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE
      TaskRoleArn:
        Fn::GetAtt:
          - TaskDefTaskRole1EDB4A67
          - Arn
    Metadata:
      aws:cdk:path: CdktestStack/TaskDef/Resource
...

Running cdk deploy fails with the below error:

CdktestStack: deploying... [1/1]
CdktestStack: creating CloudFormation changeset...
11:43:56 AM | CREATE_FAILED        | AWS::ECS::TaskDefinition           | TaskDef54694570
Resource handler returned message: "Invalid request provided: Create TaskDefinition: EphemeralStorage size should be at least 21 (Service: AmazonECS; Status Code: 400; Erro
r Code: ClientException; Request ID: d75746d2-7eac-4c17-8114-56c25b9e8c14; Proxy: null)" (RequestToken: 45f51668-4303-c8cf-2610-189ffcbb2abc, HandlerErrorCode: InvalidReque
st)


 ❌  CdktestStack failed: Error: The stack named CdktestStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Invalid request provided: Create TaskDefinition: EphemeralStorage size should be at least 21 (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: d75746d2-7eac-4c17-8114-56c25b9e8c14; Proxy: null)" (RequestToken: 45f51668-4303-c8cf-2610-189ffcbb2abc, HandlerErrorCode: InvalidRequest)
    at FullCloudFormationDeployment.monitorDeployment (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:452:10567)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Object.deployStack2 [as deployStack] (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:455:200276)
    at async /opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:455:181698

 ❌ Deployment failed: Error: The stack named CdktestStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Invalid request provided: Create TaskDefinition: EphemeralStorage size should be at least 21 (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: d75746d2-7eac-4c17-8114-56c25b9e8c14; Proxy: null)" (RequestToken: 45f51668-4303-c8cf-2610-189ffcbb2abc, HandlerErrorCode: InvalidRequest)
    at FullCloudFormationDeployment.monitorDeployment (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:452:10567)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Object.deployStack2 [as deployStack] (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:455:200276)
    at async /opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:455:181698
cdk****************************************************

So the existing validation is correct as of now.

@ashishdhingra ashishdhingra added documentation This is a problem with documentation. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. and removed documentation This is a problem with documentation. labels Sep 6, 2024
@ashishdhingra
Copy link
Contributor

@JoshMcCullough Looking at the AWS console screenshot, I now understand what is happening.

Screenshot 2024-09-06 at 12 28 59 PM
  • It specifies that By default, your tasks hosted on AWS Fargate receive a minimum of 20 GiB of ephemeral storage..
  • However, To specify a custom amount of ephemeral storage, specify a value between 21 GiB up to a maximum of 200 GiB.

In other words, when trying to explicitly specify EphemeralStorage in CloudFormation template, one needs to specify minimum value of 21 GiB. Specifying custom value as 20 GiB doesn't make sense since it would anyway default to this value if no value is specified.

Based on above understanding, the validation in CDK and the default value mentioned in documentation is correct. Please review and confirm if this issue could be closed.

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 and removed p2 needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. labels Sep 6, 2024
@JoshMcCullough
Copy link
Author

Okay. It's strange that 20 is technically valid but only if you don't specify any value.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 7, 2024
@ashishdhingra
Copy link
Contributor

Okay. It's strange that 20 is technically valid but only if you don't specify any value.

@JoshMcCullough Yes, it's really strange and was confusing in the beginning until I noticed a note in AWS console. Closing this ticket for now. Feel free to open another ticket in case you see other issues.

@ashishdhingra ashishdhingra closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2024
Copy link

github-actions bot commented Sep 9, 2024

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 Sep 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/small Small work item – less than a day of effort p3
Projects
None yet
Development

No branches or pull requests

3 participants