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

feat(ecs-patterns): add ephemeral storage support #18106

Closed
wants to merge 1 commit into from

Conversation

tapichu
Copy link

@tapichu tapichu commented Dec 20, 2021

Fargate supports a new ephemeral storage option, to request up to 200
GiB of task storage. Support for it was added to aws-ecs but not to
aws-ecs-patterns.

This change adds support for ephemeral storage, so the following
patterns can take advantage of it:

  • Application load balanced fargate service
  • Application multiple target groups fargate service
  • Network load balanced fargate service
  • Network multiple target groups fargate service
  • Queue processing fargate service
  • Scheduled fargate task

Closes #18105

Signed-off-by: Eduardo Lopez 252504+tapichu@users.noreply.github.com


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Fargate supports a new ephemeral storage option, to request up to 200
GiB of task storage. Support for it was added to aws-ecs but not to
aws-ecs-patterns.

This change adds support for ephemeral storage, so the following
patterns can take advantage of it:

* Application load balanced fargate service
* Application multiple target groups fargate service
* Network load balanced fargate service
* Network multiple target groups fargate service
* Queue processing fargate service
* Scheduled fargate task

Closes aws#18105

Signed-off-by: Eduardo Lopez <252504+tapichu@users.noreply.github.com>
@gitpod-io
Copy link

gitpod-io bot commented Dec 20, 2021

@github-actions github-actions bot added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Dec 20, 2021
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: c6e4964
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

*
* This default is set in the underlying FargateTaskDefinition construct.
*
* @default 20
Copy link
Contributor

@akash1810 akash1810 Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-ephemeralstorage.html suggests this number should be between 21 and 200:

The total amount, in GiB, of ephemeral storage to set for the task. The minimum supported value is 21 GiB and the maximum supported value is 200 GiB.

Would 20 not create a runtime error? And/or could there be some validation of ephemeralStorageGiB with an error thrown when it is not in these bounds? That is, produce a compile (synth) time error for earlier feedback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would 20 not create a runtime error? And/or could there be some validation of ephemeralStorageGiB with an error thrown when it is not in these bounds?

Yes, entering a value below 21 or above 200 will throw a validation exception:

https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-ecs/lib/fargate/fargate-task-definition.ts#L143-L145

The default value of 20 GiB comes into play when ephemeralStorageGiB is not set. By default, Fargate provides 20 GiB of ephemeral storage. That is, users only need to add ephemeralStorageGiB to their task definition when their task needs more than 20 GiB:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-task-storage.html

I documented the 20 GiB default value for ephemeral storage for consistency with aws-ecs:

https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-ecs/lib/fargate/fargate-task-definition.ts#L55-L62

You can see here that aws-ecs doesn't actually set the default value to 20 in the task definition, but rather sets ephemeralStorage to undefined when ephemeralStorageGiB is not set:

ephemeralStorage: this.ephemeralStorageGiB ? {
sizeInGiB: this.ephemeralStorageGiB,
} : undefined,

Copy link
Contributor

@akash1810 akash1810 Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽 thanks for the explanation and links!

Is there any reason the validation is only on FargateTaskDefinition and not TaskDefinition which it extends from?

The default value of 20 GiB comes into play when ephemeralStorageGiB is not set. By default, Fargate provides 20 GiB of ephemeral storage. That is, users only need to add ephemeralStorageGiB to their task definition when their task needs more than 20 GiB

I find this API quite confusing! You set this property if and only if you do not want the default value? If you do set it to the default of 20, a runtime error is seen? That's different from pretty much all other CloudFormation resources.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason the validation is only on FargateTaskDefinition and not TaskDefinition which it extends from?

I imagine that is because ephemeralStorage is a Fargate-specific option. It does not apply to non-Fargate tasks. So TaskDefinition defines the common properties for all ECS tasks and FargateTaskDefinition extends it to add the validation/options that are Fargate-specific.

I find this API quite confusing! You set this property if and only if you do not want the default value? If you do set it to the default of 20, a runtime error is seen?

I would agree this is confusing. It's probably this way to be backwards compatible. Before the ephemeralStorage option was added to the task definition, all Fargate tasks (on PV >= 1.4) would get 20 GiB of ephemeral storage by default. If ephemeralStorage had been added from day one, it would probably be a required option with no default value.

Maybe ECS can change their validation to not throw an error if ephemeralStorage is set to the default value (20), which would allow CloudFormation and the CDK to also set 20 as the default value and always set the property. The main downside would be having to maintain the default value in multiple places, and it being temporarily out of sync if ECS decides to change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that having this say 20 as the the default input and then throwing an error on that value is not the way we want to go here. I realize that the aws-ecs module did it that way, but I tend to think that should be updated instead of this one following it's lead. Let's add a default of none, since we're not plugging the number 20 in anywhere on our end and add to this doc that the minimum value here is 21. If you'd like to make the same update to the aws-ecs docs, we'd welcome that but it's certainly not mandatory.

@daveharmon
Copy link

My team is hoping to take advantage of this feature, can we please update and re-review?

@rix0rrr rix0rrr added feature-request A feature should be added or improved. p2 and removed @aws-cdk/aws-ecs-patterns Related to ecs-patterns library labels Mar 4, 2022
@madeline-k madeline-k removed their assignment Mar 23, 2022
Copy link
Contributor

@LukvonStrom LukvonStrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the Size class as some might use other sizes than GiB

@TheRealAmazonKendra TheRealAmazonKendra changed the title feat(aws-ecs-patterns): add ephemeral storage support feat(ecs-patterns): add ephemeral storage support May 13, 2022
@github-actions github-actions bot added the effort/small Small work item – less than a day of effort label May 13, 2022
Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this change! Great work on the documentation here. I just have a few changes I'd like to see on this.

@@ -76,6 +76,25 @@ If you need to encrypt the traffic between the load balancer and the ECS tasks,

Additionally, if more than one application target group are needed, instantiate one of the following:

On Fargate Platform Version 1.4.0 or later, you may specify up to 200GiB of [ephemeral storage](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-task-storage.html#fargate-task-storage-pv14):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify here that the minimum is 21 because 20 is provided by default?

@@ -125,6 +144,32 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationMultipleTargetGrou
});
```

On Fargate Platform Version 1.4.0 or later, you may specify up to 200GiB of [ephemeral storage](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-task-storage.html#fargate-task-storage-pv14):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Can you clarify here that the minimum is 21 because 20 is provided by default?

@@ -169,6 +214,21 @@ If you specify the option `recordType` you can decide if you want the construct

Additionally, if more than one network target group is needed, instantiate one of the following:

On Fargate Platform Version 1.4.0 or later, you may specify up to 200GiB of [ephemeral storage](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-task-storage.html#fargate-task-storage-pv14):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Can you clarify here that the minimum is 21 because 20 is provided by default?

@@ -253,6 +313,49 @@ const loadBalancedFargateService = new ecsPatterns.NetworkMultipleTargetGroupsFa
});
```

On Fargate Platform Version 1.4.0 or later, you may specify up to 200GiB of [ephemeral storage](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-task-storage.html#fargate-task-storage-pv14):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Can you clarify here that the minimum is 21 because 20 is provided by default?

@@ -299,6 +402,27 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ

when queue not provided by user, CDK will create a primary queue and a dead letter queue with default redrive policy and attach permission to the task to be able to access the primary queue.

On Fargate Platform Version 1.4.0 or later, you may specify up to 200GiB of [ephemeral storage](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-task-storage.html#fargate-task-storage-pv14):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Can you clarify here that the minimum is 21 because 20 is provided by default?

*
* @default 20
*/
readonly ephemeralStorageGiB?: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

@@ -115,6 +115,7 @@ describe('When Application Load Balancer', () => {
cpu: 256,
assignPublicIp: true,
memoryLimitMiB: 512,
ephemeralStorageGiB: 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add in validation failure cases for below 21 and above 200.

@@ -316,6 +316,40 @@ test('setting platform version', () => {
});
});

test('setting ephemeral storage on NLB Fargate Service', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Let's add in validation failure cases for below 21 and above 200.

@@ -350,6 +350,7 @@ testDeprecated('test Fargate queue worker service construct - with optional prop
new ecsPatterns.QueueProcessingFargateService(stack, 'Service', {
cluster,
memoryLimitMiB: 512,
ephemeralStorageGiB: 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Let's add in validation failure cases for below 21 and above 200.

@@ -92,6 +92,7 @@ test('Can create a scheduled Fargate Task - with optional props', () => {
image: ecs.ContainerImage.fromRegistry('henk'),
memoryLimitMiB: 512,
cpu: 2,
ephemeralStorageGiB: 100,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Let's add in validation failure cases for below 21 and above 200.

@TheRealAmazonKendra TheRealAmazonKendra changed the base branch from v1-main to main June 14, 2022 15:13
@olizilla
Copy link

@tapichu thank you for kicking this off! Do you have time to push it over the line? Would you prefer someone else to take it on?

@TheRealAmazonKendra
Copy link
Contributor

@olizilla This will get closed as stale soon since changes were requested. Feel free to pick this up, either building off this PR or opening a new one.

@tapichu
Copy link
Author

tapichu commented Jul 7, 2022

@tapichu thank you for kicking this off! Do you have time to push it over the line? Would you prefer someone else to take it on?

My laptop turned into a brick and it took some time to get that sorted. I should be able to work on it now.

@TheRealAmazonKendra
Copy link
Contributor

@tapichu Once you have made changes, feel free to assign this to me so that I can review it before our bots start threatening to close it.

@TheRealAmazonKendra
Copy link
Contributor

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-ecs-patterns): add support for Fargate ephemeral storage
10 participants