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): allow custom ephemeral storage for ECS Fargate services #29264

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/aws-cdk-lib/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,33 @@ const scheduledFargateTask = new ecsPatterns.ScheduledFargateTask(this, 'Schedul
},
],
});
```

### Use custom ephemeral storage for ECS Fargate tasks

You can pass a custom ephemeral storage (21GiB - 200GiB) to ECS Fargate tasks on Fargate Platform Version 1.4.0 or later.

```ts
const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
const cluster = new ecs.Cluster(stack, 'FargateCluster', { vpc });

new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'ALBFargateServiceWithCustomEphemeralStorage', {
cluster,
memoryLimitMiB: 1024,
cpu: 512,
ephemeralStorageGiB: 21,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
},
});

new ecsPatterns.NetworkLoadBalancedFargateService(stack, 'NLBFargateServiceWithCustomEphemeralStorage', {
cluster,
memoryLimitMiB: 1024,
cpu: 512,
ephemeralStorageGiB: 200,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
},
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ export interface FargateServiceBaseProps {
*/
readonly memoryLimitMiB?: number;

/**
* The amount (in GiB) of ephemeral storage to be allocated to the task.
*
* The minimum supported value is `21` GiB and the maximum supported value is `200` GiB.
*
* Only supported in Fargate platform version 1.4.0 or later.
*
* @default Undefined, in which case, the task will receive 20GiB ephemeral storage.
*/
readonly ephemeralStorageGiB?: number;

/**
* The platform version on which to run your service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu,
ephemeralStorageGiB: props.ephemeralStorageGiB,
executionRole: taskImageOptions.executionRole,
taskRole: taskImageOptions.taskRole,
family: taskImageOptions.family,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class ApplicationMultipleTargetGroupsFargateService extends ApplicationMu
this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu,
ephemeralStorageGiB: props.ephemeralStorageGiB,
executionRole: taskImageOptions.executionRole,
taskRole: taskImageOptions.taskRole,
family: taskImageOptions.family,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu,
ephemeralStorageGiB: props.ephemeralStorageGiB,
executionRole: taskImageOptions.executionRole,
taskRole: taskImageOptions.taskRole,
family: taskImageOptions.family,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class NetworkMultipleTargetGroupsFargateService extends NetworkMultipleTa
this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu,
ephemeralStorageGiB: props.ephemeralStorageGiB,
executionRole: taskImageOptions.executionRole,
taskRole: taskImageOptions.taskRole,
family: taskImageOptions.family,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
this.taskDefinition = new FargateTaskDefinition(this, 'QueueProcessingTaskDef', {
memoryLimitMiB: props.memoryLimitMiB || 512,
cpu: props.cpu || 256,
ephemeralStorageGiB: props.ephemeralStorageGiB,
family: props.family,
runtimePlatform: props.runtimePlatform,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class ScheduledFargateTask extends ScheduledTaskBase {
this.taskDefinition = new FargateTaskDefinition(this, 'ScheduledTaskDef', {
memoryLimitMiB: taskImageOptions.memoryLimitMiB || 512,
cpu: taskImageOptions.cpu || 256,
ephemeralStorageGiB: taskImageOptions.ephemeralStorageGiB,
});
this.taskDefinition.addContainer('ScheduledContainer', {
image: taskImageOptions.image,
Expand All @@ -97,6 +98,9 @@ export class ScheduledFargateTask extends ScheduledTaskBase {
if (props.memoryLimitMiB) {
Annotations.of(this).addWarningV2('@aws-cdk/aws-ecs-patterns:propertyIgnored', 'Property \'memoryLimitMiB\' is ignored, use \'scheduledFargateTaskImageOptions.memoryLimitMiB\' instead.');
}
if (props.ephemeralStorageGiB) {
Annotations.of(this).addWarningV2('@aws-cdk/aws-ecs-patterns:propertyIgnored', 'Property \'ephemeralStorageGiB\' is ignored, use \'scheduledFargateTaskImageOptions.ephemeralStorageGiB\' instead.');
}
if (props.runtimePlatform) {
Annotations.of(this).addWarningV2('@aws-cdk/aws-ecs-patterns:propertyIgnored', 'Property \'runtimePlatform\' is ignored.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ describe('Application Load Balancer', () => {
cpu: 256,
assignPublicIp: true,
memoryLimitMiB: 512,
ephemeralStorageGiB: 50,
desiredCount: 3,
enableECSManagedTags: true,
enableExecuteCommand: true,
Expand Down Expand Up @@ -349,6 +350,9 @@ describe('Application Load Balancer', () => {
},
],
Cpu: '256',
EphemeralStorage: {
SizeInGiB: 50,
},
ExecutionRoleArn: {
'Fn::GetAtt': [
'ExecutionRole605A040B',
Expand Down Expand Up @@ -847,6 +851,7 @@ describe('Network Load Balancer', () => {
cpu: 256,
assignPublicIp: true,
memoryLimitMiB: 512,
ephemeralStorageGiB: 80,
desiredCount: 3,
enableECSManagedTags: true,
enableExecuteCommand: true,
Expand Down Expand Up @@ -955,6 +960,9 @@ describe('Network Load Balancer', () => {
},
],
Cpu: '256',
EphemeralStorage: {
SizeInGiB: 80,
},
ExecutionRoleArn: {
'Fn::GetAtt': [
'ExecutionRole605A040B',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ testDeprecated('test Fargate queue worker service construct - with optional prop
new ecsPatterns.QueueProcessingFargateService(stack, 'Service', {
cluster,
memoryLimitMiB: 512,
ephemeralStorageGiB: 100,
image: ecs.ContainerImage.fromRegistry('test'),
command: ['-c', '4', 'amazon.com'],
enableLogging: false,
Expand Down Expand Up @@ -565,6 +566,9 @@ testDeprecated('test Fargate queue worker service construct - with optional prop
}),
],
Family: 'fargate-task-family',
EphemeralStorage: {
SizeInGiB: 100,
},
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
environment: { TRIGGER: 'CloudWatch Events' },
},
desiredTaskCount: 2,
Expand Down Expand Up @@ -162,6 +163,9 @@ test('Can create a scheduled Fargate Task - with optional props', () => {
Name: 'ScheduledContainer',
},
],
EphemeralStorage: {
SizeInGiB: 100,
},
});
});

Expand Down
Loading