diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 1ab0849a26ffd..eb7e9dccdc503 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -144,9 +144,11 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, - logging: logDriver, + cpu: props.cpu, + memoryLimitMiB: props.memoryLimitMiB, environment: taskImageOptions.environment, secrets: taskImageOptions.secrets, + logging: logDriver, dockerLabels: taskImageOptions.dockerLabels, }); container.addPortMappings({ diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts index 9299cfc2e3023..b527daabf0e0e 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts @@ -134,9 +134,11 @@ export class ApplicationMultipleTargetGroupsFargateService extends ApplicationMu const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, - logging: this.logDriver, + cpu: props.cpu, + memoryLimitMiB: props.memoryLimitMiB, environment: taskImageOptions.environment, secrets: taskImageOptions.secrets, + logging: this.logDriver, dockerLabels: taskImageOptions.dockerLabels, }); if (taskImageOptions.containerPorts) { diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts index 2aefba07cb42e..203d185a3a6be 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts @@ -131,9 +131,11 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, - logging: logDriver, + cpu: props.cpu, + memoryLimitMiB: props.memoryLimitMiB, environment: taskImageOptions.environment, secrets: taskImageOptions.secrets, + logging: logDriver, dockerLabels: taskImageOptions.dockerLabels, }); container.addPortMappings({ diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-multiple-target-groups-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-multiple-target-groups-fargate-service.ts index 4e610dac65154..eca9e6b037d37 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-multiple-target-groups-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-multiple-target-groups-fargate-service.ts @@ -134,9 +134,11 @@ export class NetworkMultipleTargetGroupsFargateService extends NetworkMultipleTa const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, - logging: this.logDriver, + cpu: props.cpu, + memoryLimitMiB: props.memoryLimitMiB, environment: taskImageOptions.environment, secrets: taskImageOptions.secrets, + logging: this.logDriver, dockerLabels: taskImageOptions.dockerLabels, }); if (taskImageOptions.containerPorts) { diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts index 89b666fd39405..04369a76216b8 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts @@ -120,10 +120,13 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase { constructor(scope: Construct, id: string, props: QueueProcessingFargateServiceProps) { super(scope, id, props); + const cpu = props.cpu || 256; + const memoryLimitMiB = props.memoryLimitMiB || 512; + // Create a Task Definition for the container to start this.taskDefinition = new FargateTaskDefinition(this, 'QueueProcessingTaskDef', { - memoryLimitMiB: props.memoryLimitMiB || 512, - cpu: props.cpu || 256, + cpu, + memoryLimitMiB, family: props.family, }); @@ -131,6 +134,8 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase { this.taskDefinition.addContainer(containerName, { image: props.image, + cpu, + memoryLimitMiB, command: props.command, environment: this.environment, secrets: this.secrets, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts index 7a5a018920e7a..6eeb58e91636f 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts @@ -111,12 +111,17 @@ export class ScheduledFargateTask extends ScheduledTaskBase { this.taskDefinition = props.scheduledFargateTaskDefinitionOptions.taskDefinition; } else if (props.scheduledFargateTaskImageOptions) { const taskImageOptions = props.scheduledFargateTaskImageOptions; + const cpu = taskImageOptions.cpu || 256; + const memoryLimitMiB = taskImageOptions.memoryLimitMiB || 512; + this.taskDefinition = new FargateTaskDefinition(this, 'ScheduledTaskDef', { - memoryLimitMiB: taskImageOptions.memoryLimitMiB || 512, - cpu: taskImageOptions.cpu || 256, + memoryLimitMiB, + cpu, }); this.taskDefinition.addContainer('ScheduledContainer', { image: taskImageOptions.image, + memoryLimitMiB, + cpu, command: taskImageOptions.command, environment: taskImageOptions.environment, secrets: taskImageOptions.secrets, diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/l3s.test.ts b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/l3s.test.ts index ccd24c1f6dd90..48f15ba409a1a 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/l3s.test.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/l3s.test.ts @@ -499,6 +499,8 @@ test('test Fargate loadbalanced construct', () => { // WHEN new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { cluster, + cpu: 1024, + memoryLimitMiB: 2048, taskImageOptions: { image: ecs.ContainerImage.fromRegistry('test'), environment: { @@ -515,6 +517,11 @@ test('test Fargate loadbalanced construct', () => { Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { ContainerDefinitions: [ Match.objectLike({ + Cpu: 1024, + DockerLabels: { + label1: 'labelValue1', + label2: 'labelValue2', + }, Environment: [ { Name: 'TEST_ENVIRONMENT_VARIABLE1', @@ -525,6 +532,7 @@ test('test Fargate loadbalanced construct', () => { Value: 'test environment variable 2 value', }, ], + Image: 'test', LogConfiguration: { LogDriver: 'awslogs', Options: { @@ -533,12 +541,11 @@ test('test Fargate loadbalanced construct', () => { 'awslogs-region': { Ref: 'AWS::Region' }, }, }, - DockerLabels: { - label1: 'labelValue1', - label2: 'labelValue2', - }, + Memory: 2048, }), ], + Cpu: '1024', + Memory: '2048', }); Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/alb-fargate-service-https.integ.snapshot/aws-ecs-integ-alb-fg-https.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/alb-fargate-service-https.integ.snapshot/aws-ecs-integ-alb-fg-https.template.json index b43512a5773e7..59f9681d49745 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/alb-fargate-service-https.integ.snapshot/aws-ecs-integ-alb-fg-https.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/alb-fargate-service-https.integ.snapshot/aws-ecs-integ-alb-fg-https.template.json @@ -636,6 +636,7 @@ } } }, + "Memory": 512, "Name": "web", "PortMappings": [ { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/circuit-breaker-load-balanced-fargate-service.integ.snapshot/aws-ecs-integ.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/circuit-breaker-load-balanced-fargate-service.integ.snapshot/aws-ecs-integ.template.json index 972b0642021bd..800bc588a7f46 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/circuit-breaker-load-balanced-fargate-service.integ.snapshot/aws-ecs-integ.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/circuit-breaker-load-balanced-fargate-service.integ.snapshot/aws-ecs-integ.template.json @@ -529,6 +529,7 @@ } } }, + "Memory": 512, "Name": "web", "PortMappings": [ { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/circuit-breaker-queue-processing-fargate-service.integ.snapshot/aws-ecs-patterns-queue.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/circuit-breaker-queue-processing-fargate-service.integ.snapshot/aws-ecs-patterns-queue.template.json index 64ce41f985ed3..f2afafcbc61e4 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/circuit-breaker-queue-processing-fargate-service.integ.snapshot/aws-ecs-patterns-queue.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/circuit-breaker-queue-processing-fargate-service.integ.snapshot/aws-ecs-patterns-queue.template.json @@ -461,6 +461,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 256, "Environment": [ { "Name": "QUEUE_NAME", @@ -504,6 +505,7 @@ } } }, + "Memory": 512, "Name": "QueueProcessingContainer" } ], diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/executionrole.integ.snapshot/aws-ecs-integ.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/executionrole.integ.snapshot/aws-ecs-integ.template.json index b8aca663dd829..e71893a8f3063 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/executionrole.integ.snapshot/aws-ecs-integ.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/executionrole.integ.snapshot/aws-ecs-integ.template.json @@ -564,6 +564,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -578,6 +579,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-autocreate.integ.snapshot/aws-ecs-integ-l3-autocreate.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-autocreate.integ.snapshot/aws-ecs-integ-l3-autocreate.template.json index 1f9ca9150aa38..5efb07639c727 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-autocreate.integ.snapshot/aws-ecs-integ-l3-autocreate.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-autocreate.integ.snapshot/aws-ecs-integ-l3-autocreate.template.json @@ -129,6 +129,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -143,6 +144,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { @@ -775,6 +777,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -789,6 +792,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-capacity-provider-strategies.integ.snapshot/aws-ecs-integ-lb-fargate.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-capacity-provider-strategies.integ.snapshot/aws-ecs-integ-lb-fargate.template.json index 78a971a6fc95e..41f957c530db4 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-capacity-provider-strategies.integ.snapshot/aws-ecs-integ-lb-fargate.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-capacity-provider-strategies.integ.snapshot/aws-ecs-integ-lb-fargate.template.json @@ -528,6 +528,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -542,6 +543,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { @@ -799,6 +801,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -813,6 +816,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-vpconly.integ.snapshot/aws-ecs-integ-l3-vpconly.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-vpconly.integ.snapshot/aws-ecs-integ-l3-vpconly.template.json index ba315a320a5fc..017474dfeb2d3 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-vpconly.integ.snapshot/aws-ecs-integ-l3-vpconly.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3-vpconly.integ.snapshot/aws-ecs-integ-l3-vpconly.template.json @@ -512,6 +512,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -526,6 +527,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { @@ -775,6 +777,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -789,6 +792,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3.integ.snapshot/aws-ecs-integ-lb-fargate.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3.integ.snapshot/aws-ecs-integ-lb-fargate.template.json index 5d9f94b76397a..5055f98fddfed 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3.integ.snapshot/aws-ecs-integ-lb-fargate.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/l3.integ.snapshot/aws-ecs-integ-lb-fargate.template.json @@ -515,6 +515,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -529,6 +530,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { @@ -775,6 +777,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 512, "Essential": true, "Image": "amazon/amazon-ecs-sample", "LogConfiguration": { @@ -789,6 +792,7 @@ } } }, + "Memory": 1024, "Name": "web", "PortMappings": [ { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/multiple-network-load-balanced-fargate-service.integ.snapshot/aws-ecs-integ.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/multiple-network-load-balanced-fargate-service.integ.snapshot/aws-ecs-integ.template.json index 2a503a6b25d24..45e3fbfbb202a 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/multiple-network-load-balanced-fargate-service.integ.snapshot/aws-ecs-integ.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/multiple-network-load-balanced-fargate-service.integ.snapshot/aws-ecs-integ.template.json @@ -530,6 +530,7 @@ } } }, + "Memory": 512, "Name": "web", "PortMappings": [ { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service-isolated.integ.snapshot/aws-ecs-patterns-queue-isolated.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service-isolated.integ.snapshot/aws-ecs-patterns-queue-isolated.template.json index 930d342cdb091..01f170e4ad3c5 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service-isolated.integ.snapshot/aws-ecs-patterns-queue-isolated.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service-isolated.integ.snapshot/aws-ecs-patterns-queue-isolated.template.json @@ -770,6 +770,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 256, "Environment": [ { "Name": "QUEUE_NAME", @@ -813,6 +814,7 @@ } } }, + "Memory": 512, "Name": "QueueProcessingContainer" } ], diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service-public.integ.snapshot/aws-ecs-patterns-queue-public.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service-public.integ.snapshot/aws-ecs-patterns-queue-public.template.json index 1bff926aba21a..68c10a9aac5e8 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service-public.integ.snapshot/aws-ecs-patterns-queue-public.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service-public.integ.snapshot/aws-ecs-patterns-queue-public.template.json @@ -461,6 +461,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 256, "Environment": [ { "Name": "QUEUE_NAME", @@ -513,6 +514,7 @@ } } }, + "Memory": 512, "Name": "QueueProcessingContainer" } ], diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service.integ.snapshot/aws-ecs-patterns-queue.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service.integ.snapshot/aws-ecs-patterns-queue.template.json index 4a91c2fabee6f..d635ba9043349 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service.integ.snapshot/aws-ecs-patterns-queue.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/queue-processing-fargate-service.integ.snapshot/aws-ecs-patterns-queue.template.json @@ -461,6 +461,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 256, "Environment": [ { "Name": "QUEUE_NAME", @@ -504,6 +505,7 @@ } } }, + "Memory": 512, "Name": "QueueProcessingContainer" } ], diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/scheduled-fargate-task.integ.snapshot/aws-fargate-integ.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/scheduled-fargate-task.integ.snapshot/aws-fargate-integ.template.json index 669810a5d8785..3fb1642063cf0 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/scheduled-fargate-task.integ.snapshot/aws-fargate-integ.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/scheduled-fargate-task.integ.snapshot/aws-fargate-integ.template.json @@ -285,6 +285,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 256, "Environment": [ { "Name": "TRIGGER", @@ -323,6 +324,7 @@ } } }, + "Memory": 512, "Name": "ScheduledContainer" } ], diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/scheduled-fargate-task.lit.integ.snapshot/aws-fargate-integ.template.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/scheduled-fargate-task.lit.integ.snapshot/aws-fargate-integ.template.json index 669810a5d8785..3fb1642063cf0 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/scheduled-fargate-task.lit.integ.snapshot/aws-fargate-integ.template.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/scheduled-fargate-task.lit.integ.snapshot/aws-fargate-integ.template.json @@ -285,6 +285,7 @@ "Properties": { "ContainerDefinitions": [ { + "Cpu": 256, "Environment": [ { "Name": "TRIGGER", @@ -323,6 +324,7 @@ } } }, + "Memory": 512, "Name": "ScheduledContainer" } ],