From f8ccdf2511a7088c4f7248ba92c7c47296474468 Mon Sep 17 00:00:00 2001 From: Piradeep Kandasamy Date: Tue, 20 Aug 2019 09:20:06 -0700 Subject: [PATCH] Add TaskDef as a property on the construct --- .../lib/ecs/application-load-balanced-ecs-service.ts | 12 ++++++++---- .../lib/ecs/network-load-balanced-ecs-service.ts | 12 ++++++++---- .../lib/ecs/queue-processing-ecs-service.ts | 12 ++++++++---- .../aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts | 2 +- .../application-load-balanced-fargate-service.ts | 10 +++++++--- .../fargate/network-load-balanced-fargate-service.ts | 10 +++++++--- .../lib/fargate/queue-processing-fargate-service.ts | 12 ++++++++---- .../lib/fargate/scheduled-fargate-task.ts | 5 ++--- 8 files changed, 49 insertions(+), 26 deletions(-) diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts index 28ea3fcc221be..904dc8844d533 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts @@ -59,9 +59,13 @@ export interface ApplicationLoadBalancedEc2ServiceProps extends ApplicationLoadB export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedServiceBase { /** - * The ECS service in this construct + * The EC2 service in this construct. */ public readonly service: Ec2Service; + /** + * The EC2 Task Definition in this construct. + */ + public readonly taskDefinition: Ec2TaskDefinition; /** * Constructs a new instance of the ApplicationLoadBalancedEc2Service class. @@ -69,13 +73,13 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe constructor(scope: Construct, id: string, props: ApplicationLoadBalancedEc2ServiceProps) { super(scope, id, props); - const taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', { + this.taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', { executionRole: props.executionRole, taskRole: props.taskRole }); const containerName = props.containerName !== undefined ? props.containerName : 'web'; - const container = taskDefinition.addContainer(containerName, { + const container = this.taskDefinition.addContainer(containerName, { image: props.image, cpu: props.cpu, memoryLimitMiB: props.memoryLimitMiB, @@ -91,7 +95,7 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe this.service = new Ec2Service(this, "Service", { cluster: this.cluster, desiredCount: this.desiredCount, - taskDefinition, + taskDefinition: this.taskDefinition, assignPublicIp: this.assignPublicIp, serviceName: props.serviceName, healthCheckGracePeriod: props.healthCheckGracePeriod, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts index 2b6fa77fc946c..81bd7eaf98b9b 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts @@ -59,9 +59,13 @@ export interface NetworkLoadBalancedEc2ServiceProps extends NetworkLoadBalancedS export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBase { /** - * The ECS service in this construct + * The ECS service in this construct. */ public readonly service: Ec2Service; + /** + * The EC2 Task Definition in this construct. + */ + public readonly taskDefinition: Ec2TaskDefinition; /** * Constructs a new instance of the NetworkLoadBalancedEc2Service class. @@ -69,13 +73,13 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas constructor(scope: Construct, id: string, props: NetworkLoadBalancedEc2ServiceProps) { super(scope, id, props); - const taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', { + this.taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', { executionRole: props.executionRole, taskRole: props.taskRole }); const containerName = props.containerName !== undefined ? props.containerName : 'web'; - const container = taskDefinition.addContainer(containerName, { + const container = this.taskDefinition.addContainer(containerName, { image: props.image, cpu: props.cpu, memoryLimitMiB: props.memoryLimitMiB, @@ -91,7 +95,7 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas this.service = new Ec2Service(this, "Service", { cluster: this.cluster, desiredCount: this.desiredCount, - taskDefinition, + taskDefinition: this.taskDefinition, assignPublicIp: this.assignPublicIp, serviceName: props.serviceName, healthCheckGracePeriod: props.healthCheckGracePeriod, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts index 2002b37fd5949..932216bd9d25e 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts @@ -59,9 +59,13 @@ export interface QueueProcessingEc2ServiceProps extends QueueProcessingServiceBa export class QueueProcessingEc2Service extends QueueProcessingServiceBase { /** - * The ECS service in this construct + * The EC2 service in this construct. */ public readonly service: Ec2Service; + /** + * The EC2 task definition in this construct + */ + public readonly taskDefinition: Ec2TaskDefinition; /** * Constructs a new instance of the QueueProcessingEc2Service class. @@ -70,8 +74,8 @@ export class QueueProcessingEc2Service extends QueueProcessingServiceBase { super(scope, id, props); // Create a Task Definition for the container to start - const taskDefinition = new Ec2TaskDefinition(this, 'QueueProcessingTaskDef'); - taskDefinition.addContainer('QueueProcessingContainer', { + this.taskDefinition = new Ec2TaskDefinition(this, 'QueueProcessingTaskDef'); + this.taskDefinition.addContainer('QueueProcessingContainer', { image: props.image, memoryLimitMiB: props.memoryLimitMiB, memoryReservationMiB: props.memoryReservationMiB, @@ -87,7 +91,7 @@ export class QueueProcessingEc2Service extends QueueProcessingServiceBase { this.service = new Ec2Service(this, 'QueueProcessingService', { cluster: this.cluster, desiredCount: this.desiredCount, - taskDefinition + taskDefinition: this.taskDefinition }); this.configureAutoscalingForService(this.service); } diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts index feeb5ee43740b..65e182bfbbe2b 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts @@ -46,7 +46,7 @@ export interface ScheduledEc2TaskProps extends ScheduledTaskBaseProps { export class ScheduledEc2Task extends ScheduledTaskBase { /** - * The ECS service in this construct + * The EC2 task definition in this construct. */ public readonly taskDefinition: Ec2TaskDefinition; 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 2cef12926461f..28c71e9c44677 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 @@ -59,6 +59,10 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc * The Fargate service in this construct. */ public readonly service: FargateService; + /** + * The Fargate task definition in this construct. + */ + public readonly taskDefinition: FargateTaskDefinition; /** * Constructs a new instance of the ApplicationLoadBalancedFargateService class. @@ -66,7 +70,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc constructor(scope: Construct, id: string, props: ApplicationLoadBalancedFargateServiceProps) { super(scope, id, props); - const taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { + this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { memoryLimitMiB: props.memoryLimitMiB, cpu: props.cpu, executionRole: props.executionRole, @@ -74,7 +78,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc }); const containerName = props.containerName !== undefined ? props.containerName : 'web'; - const container = taskDefinition.addContainer(containerName, { + const container = this.taskDefinition.addContainer(containerName, { image: props.image, logging: this.logDriver, environment: props.environment, @@ -87,7 +91,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc this.service = new FargateService(this, "Service", { cluster: this.cluster, desiredCount: this.desiredCount, - taskDefinition, + taskDefinition: this.taskDefinition, assignPublicIp: this.assignPublicIp, serviceName: props.serviceName, healthCheckGracePeriod: props.healthCheckGracePeriod, 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 df0ea5728fb0f..5950543023c11 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 @@ -59,6 +59,10 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic * The Fargate service in this construct. */ public readonly service: FargateService; + /** + * The Fargate task definition in this construct. + */ + public readonly taskDefinition: FargateTaskDefinition; /** * Constructs a new instance of the NetworkLoadBalancedFargateService class. @@ -66,7 +70,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic constructor(scope: Construct, id: string, props: NetworkLoadBalancedFargateServiceProps) { super(scope, id, props); - const taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { + this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { memoryLimitMiB: props.memoryLimitMiB, cpu: props.cpu, executionRole: props.executionRole, @@ -74,7 +78,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic }); const containerName = props.containerName !== undefined ? props.containerName : 'web'; - const container = taskDefinition.addContainer(containerName, { + const container = this.taskDefinition.addContainer(containerName, { image: props.image, logging: this.logDriver, environment: props.environment, @@ -87,7 +91,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic this.service = new FargateService(this, "Service", { cluster: this.cluster, desiredCount: this.desiredCount, - taskDefinition, + taskDefinition: this.taskDefinition, assignPublicIp: this.assignPublicIp, serviceName: props.serviceName, healthCheckGracePeriod: props.healthCheckGracePeriod, 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 27647cd4815fb..4c0564893adbc 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 @@ -49,9 +49,13 @@ export interface QueueProcessingFargateServiceProps extends QueueProcessingServi */ export class QueueProcessingFargateService extends QueueProcessingServiceBase { /** - * The Fargate service in this construct + * The Fargate service in this construct. */ public readonly service: FargateService; + /** + * The Fargate task definition in this construct. + */ + public readonly taskDefinition: FargateTaskDefinition; /** * Constructs a new instance of the QueueProcessingFargateService class. @@ -60,11 +64,11 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase { super(scope, id, props); // Create a Task Definition for the container to start - const taskDefinition = new FargateTaskDefinition(this, 'QueueProcessingTaskDef', { + this.taskDefinition = new FargateTaskDefinition(this, 'QueueProcessingTaskDef', { memoryLimitMiB: props.memoryLimitMiB || 512, cpu: props.cpu || 256, }); - taskDefinition.addContainer('QueueProcessingContainer', { + this.taskDefinition.addContainer('QueueProcessingContainer', { image: props.image, command: props.command, environment: this.environment, @@ -77,7 +81,7 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase { this.service = new FargateService(this, 'QueueProcessingFargateService', { cluster: this.cluster, desiredCount: this.desiredCount, - taskDefinition + taskDefinition: this.taskDefinition }); this.configureAutoscalingForService(this.service); } 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 0ff7f087e96a1..b295a725fbabe 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 @@ -37,7 +37,7 @@ export interface ScheduledFargateTaskProps extends ScheduledTaskBaseProps { */ export class ScheduledFargateTask extends ScheduledTaskBase { /** - * The ECS service in this construct + * The Fargate task definition in this construct. */ public readonly taskDefinition: FargateTaskDefinition; @@ -47,8 +47,7 @@ export class ScheduledFargateTask extends ScheduledTaskBase { constructor(scope: Construct, id: string, props: ScheduledFargateTaskProps) { super(scope, id, props); - // Create a Task Definition for the container to start, also creates a log driver - this. taskDefinition = new FargateTaskDefinition(this, 'ScheduledTaskDef', { + this.taskDefinition = new FargateTaskDefinition(this, 'ScheduledTaskDef', { memoryLimitMiB: props.memoryLimitMiB || 512, cpu: props.cpu || 256, });