aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.72k stars 3.94k forks source link

ecs_patterns.ApplicationLoadBalancedFargateService: cannot set ephemeral storage #25403

Open raunakdoesdev opened 1 year ago

raunakdoesdev commented 1 year ago

Describe the bug

ECS fargate task definitions allow you to specify the amount of ephemeral storage to provide, the current patterns do not provide this. I believe the relevant type to change would be this one: https://github.com/aws/aws-cdk/blob/04323c44da6b8821a361a36bb2feadde77d54c35/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts#L4

Expected Behavior

I expected to be able to set ephemeral storage directly from within the ApplicationLoadBalancedFargateService props.

Current Behavior

I can't do the above.

Reproduction Steps

Set ephemeral storage directly from within the ApplicationLoadBalancedFargateService props.

Possible Solution

Quite simple... just add the prop!

Additional Information/Context

No response

CDK CLI Version

2.73.0

Framework Version

No response

Node.js Version

v18.16.0

OS

MacOS

Language

Typescript

Language Version

No response

Other information

I can probably write up a pull request for this in the next week or two but am kinda swamped with work. It's a pretty simple fix, might make for a good first issue for someone!

raunakdoesdev commented 1 year ago

Good workaround:

    const taskDefinition = fargateService.taskDefinition.node
      .defaultChild as ecs.CfnTaskDefinition;
    taskDefinition.addPropertyOverride("EphemeralStorage", {
      SizeInGiB: 100,
    });

Though not ideal since it's not typesafe...

peterwoodworth commented 1 year ago

Our L3 constructs will make some opinionated choices like this, this is something we could add but typically if you need fine-grained control then building patterns with your own L2 constructs is a better choice if the modifications you need to make aren't easily achievable with escape hatches

We can always reconsider however, we use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.

rishi-kulkarni commented 1 year ago

This would definitely be useful to me. For anyone else using CDK from Go, here's the Go version of the above workaround:

var taskDefinition awsecs.CfnTaskDefinition
jsii.UnsafeCast(fargateService.TaskDefinition().Node().DefaultChild(), &taskDefinition)
taskDefinition.SetEphemeralStorage(
    &awsecs.CfnTaskDefinition_EphemeralStorageProperty{SizeInGiB: jsii.Number(25)},
)