diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.expected.json b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.expected.json index 77c4d9b07b13f..2b95abce1188d 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.expected.json +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/integ.pipeline-ecs-deploy.expected.json @@ -232,12 +232,7 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], - "MountPoints": [], - "Name": "Container", - "PortMappings": [], - "Ulimits": [], - "VolumesFrom": [] + "Name": "Container" } ], "Cpu": "256", diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.scheduled-ecs-task.lit.expected.json b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.scheduled-ecs-task.lit.expected.json index 7327cc7d3fac6..adafa4088df52 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.scheduled-ecs-task.lit.expected.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.scheduled-ecs-task.lit.expected.json @@ -671,7 +671,6 @@ ], "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -685,11 +684,7 @@ } }, "Memory": 512, - "MountPoints": [], - "Name": "ScheduledContainer", - "PortMappings": [], - "Ulimits": [], - "VolumesFrom": [] + "Name": "ScheduledContainer" } ], "ExecutionRoleArn": { diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.scheduled-ecs-task.ts b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.scheduled-ecs-task.ts index 2fbfd50692e0d..9fee74eb5af8d 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.scheduled-ecs-task.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.scheduled-ecs-task.ts @@ -44,7 +44,6 @@ export = { { Essential: true, Image: "henk", - Links: [], LogConfiguration: { LogDriver: "awslogs", Options: { @@ -58,11 +57,7 @@ export = { } }, Memory: 512, - MountPoints: [], - Name: "ScheduledContainer", - PortMappings: [], - Ulimits: [], - VolumesFrom: [] + Name: "ScheduledContainer" } ] })); @@ -117,7 +112,6 @@ export = { ], Essential: true, Image: "henk", - Links: [], LogConfiguration: { LogDriver: "awslogs", Options: { @@ -131,11 +125,7 @@ export = { } }, Memory: 512, - MountPoints: [], - Name: "ScheduledContainer", - PortMappings: [], - Ulimits: [], - VolumesFrom: [] + Name: "ScheduledContainer" } ] })); @@ -165,7 +155,6 @@ export = { { Essential: true, Image: "henk", - Links: [], LogConfiguration: { LogDriver: "awslogs", Options: { @@ -179,11 +168,7 @@ export = { } }, MemoryReservation: 512, - MountPoints: [], - Name: "ScheduledContainer", - PortMappings: [], - Ulimits: [], - VolumesFrom: [] + Name: "ScheduledContainer" } ] })); @@ -219,7 +204,6 @@ export = { ], Essential: true, Image: "henk", - Links: [], LogConfiguration: { LogDriver: "awslogs", Options: { @@ -233,11 +217,7 @@ export = { } }, MemoryReservation: 512, - MountPoints: [], - Name: "ScheduledContainer", - PortMappings: [], - Ulimits: [], - VolumesFrom: [] + Name: "ScheduledContainer" } ] })); diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json index e2de65df98fb2..e8363a409563e 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json @@ -584,7 +584,6 @@ ] ] }, - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -597,16 +596,13 @@ } } }, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 8000, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "256", diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.expected.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.expected.json index dff14f1ca0029..f152a3c201577 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.expected.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.expected.json @@ -549,7 +549,6 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -562,16 +561,13 @@ } } }, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "512", diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-autocreate.expected.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-autocreate.expected.json index a9cd08b3bad06..b8e8c59ed8337 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-autocreate.expected.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-autocreate.expected.json @@ -134,7 +134,6 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -147,16 +146,13 @@ } } }, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "512", @@ -813,7 +809,6 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -826,16 +821,13 @@ } } }, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "512", diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-vpconly.expected.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-vpconly.expected.json index f1c64c6ee230e..e7f468acf6245 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-vpconly.expected.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-vpconly.expected.json @@ -477,7 +477,6 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -490,16 +489,13 @@ } } }, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "512", @@ -1156,7 +1152,6 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -1169,16 +1164,13 @@ } } }, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "512", @@ -1492,7 +1484,6 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -1505,16 +1496,13 @@ } } }, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "512", diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3.expected.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3.expected.json index 829b0cf2739d0..310c9e0578b44 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3.expected.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3.expected.json @@ -480,7 +480,6 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -493,16 +492,13 @@ } } }, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "512", diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.scheduled-fargate-task.lit.expected.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.scheduled-fargate-task.lit.expected.json index 689641c744b28..ae6840c20dec3 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.scheduled-fargate-task.lit.expected.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.scheduled-fargate-task.lit.expected.json @@ -368,7 +368,6 @@ ] ] }, - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -381,11 +380,7 @@ } } }, - "MountPoints": [], - "Name": "ScheduledContainer", - "PortMappings": [], - "Ulimits": [], - "VolumesFrom": [] + "Name": "ScheduledContainer" } ], "Cpu": "256", diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts index 835287b2e4284..dacb85765d2df 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts @@ -41,7 +41,6 @@ export = { { Essential: true, Image: "henk", - Links: [], LogConfiguration: { LogDriver: "awslogs", Options: { @@ -54,11 +53,7 @@ export = { } } }, - MountPoints: [], - Name: "ScheduledContainer", - PortMappings: [], - Ulimits: [], - VolumesFrom: [] + Name: "ScheduledContainer" } ] })); @@ -109,7 +104,6 @@ export = { ], Essential: true, Image: "henk", - Links: [], LogConfiguration: { LogDriver: "awslogs", Options: { @@ -122,11 +116,7 @@ export = { } } }, - MountPoints: [], - Name: "ScheduledContainer", - PortMappings: [], - Ulimits: [], - VolumesFrom: [] + Name: "ScheduledContainer" } ] })); @@ -152,7 +142,6 @@ export = { { Essential: true, Image: "henk", - Links: [], LogConfiguration: { LogDriver: "awslogs", Options: { @@ -165,11 +154,7 @@ export = { } } }, - MountPoints: [], - Name: "ScheduledContainer", - PortMappings: [], - Ulimits: [], - VolumesFrom: [] + Name: "ScheduledContainer" } ] })); @@ -201,7 +186,6 @@ export = { ], Essential: true, Image: "henk", - Links: [], LogConfiguration: { LogDriver: "awslogs", Options: { @@ -214,11 +198,7 @@ export = { } } }, - MountPoints: [], - Name: "ScheduledContainer", - PortMappings: [], - Ulimits: [], - VolumesFrom: [] + Name: "ScheduledContainer" } ] })); diff --git a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts index 02d887fe9721d..9189666f9bf0a 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts @@ -310,7 +310,7 @@ export abstract class BaseService extends Resource this.loadBalancers.push({ targetGroupArn: targetGroup.targetGroupArn, - containerName: this.taskDefinition.defaultContainer!.node.id, + containerName: this.taskDefinition.defaultContainer!.containerName, containerPort: this.taskDefinition.defaultContainer!.containerPort, }); @@ -378,7 +378,7 @@ export abstract class BaseService extends Resource // If the task definition that your service task specifies uses the AWSVPC network mode and a type SRV DNS record is // used, you must specify a containerName and containerPort combination - const containerName = dnsRecordType === cloudmap.DnsRecordType.SRV ? this.taskDefinition.defaultContainer!.node.id : undefined; + const containerName = dnsRecordType === cloudmap.DnsRecordType.SRV ? this.taskDefinition.defaultContainer!.containerName : undefined; const containerPort = dnsRecordType === cloudmap.DnsRecordType.SRV ? this.taskDefinition.defaultContainer!.containerPort : undefined; const cloudmapService = new cloudmap.Service(this, 'CloudmapService', { diff --git a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts index 3694e754174a7..19154b89daa73 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts @@ -376,7 +376,7 @@ export class TaskDefinition extends TaskDefinitionBase { // Container sizes for (const container of this.containers) { if (!container.memoryLimitSpecified) { - ret.push(`ECS Container ${container.node.id} must have at least one of 'memoryLimitMiB' or 'memoryReservationMiB' specified`); + ret.push(`ECS Container ${container.containerName} must have at least one of 'memoryLimitMiB' or 'memoryReservationMiB' specified`); } } } diff --git a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts index 6cf207ad4d1fd..bee0698be7f63 100644 --- a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts @@ -259,23 +259,28 @@ export class ContainerDefinition extends cdk.Construct { /** * The mount points for data volumes in your container. */ - public readonly mountPoints = new Array(); + public readonly mountPoints = new Array(); /** * The list of port mappings for the container. Port mappings allow containers to access ports * on the host container instance to send or receive traffic. */ - public readonly portMappings = new Array(); + public readonly portMappings = new Array(); - /** - * The data volumes to mount from another container in the same task definition. - */ - public readonly volumesFrom = new Array(); + /** + * The data volumes to mount from another container in the same task definition. + */ + public readonly volumesFrom = new Array(); - /** - * An array of ulimits to set in the container. - */ - public readonly ulimits = new Array(); + /** + * An array of ulimits to set in the container. + */ + public readonly ulimits = new Array(); + + /** + * An array dependencies defined for container startup and shutdown. + */ + public readonly containerDependencies = new Array(); /** * Specifies whether the container will be marked essential. @@ -289,6 +294,11 @@ export class ContainerDefinition extends cdk.Construct { */ public readonly essential: boolean; + /** + * The name of this container + */ + public readonly containerName: string; + /** * Whether there was at least one memory limit specified in this definition */ @@ -317,6 +327,7 @@ export class ContainerDefinition extends cdk.Construct { this.taskDefinition = props.taskDefinition; this.memoryLimitSpecified = props.memoryLimitMiB !== undefined || props.memoryReservationMiB !== undefined; this.linuxParameters = props.linuxParameters; + this.containerName = this.node.id; this.imageConfig = props.image.bind(this, this); if (props.logging) { @@ -336,9 +347,9 @@ export class ContainerDefinition extends cdk.Construct { throw new Error(`You must use network mode Bridge to add container links.`); } if (alias !== undefined) { - this.links.push(`${container.node.id}:${alias}`); + this.links.push(`${container.containerName}:${alias}`); } else { - this.links.push(`${container.node.id}`); + this.links.push(`${container.containerName}`); } } @@ -403,6 +414,13 @@ export class ContainerDefinition extends cdk.Construct { this.ulimits.push(...ulimits); } + /** + * This method adds one or more container dependencies to the container. + */ + public addContainerDependencies(...containerDependencies: ContainerDependency[]) { + this.containerDependencies.push(...containerDependencies); + } + /** * This method adds one or more volumes to the container. */ @@ -424,7 +442,7 @@ export class ContainerDefinition extends cdk.Construct { */ public get ingressPort(): number { if (this.portMappings.length === 0) { - throw new Error(`Container ${this.node.id} hasn't defined any ports. Call addPortMappings().`); + throw new Error(`Container ${this.containerName} hasn't defined any ports. Call addPortMappings().`); } const defaultPortMapping = this.portMappings[0]; @@ -443,7 +461,7 @@ export class ContainerDefinition extends cdk.Construct { */ public get containerPort(): number { if (this.portMappings.length === 0) { - throw new Error(`Container ${this.node.id} hasn't defined any ports. Call addPortMappings().`); + throw new Error(`Container ${this.containerName} hasn't defined any ports. Call addPortMappings().`); } const defaultPortMapping = this.portMappings[0]; return defaultPortMapping.containerPort; @@ -459,6 +477,7 @@ export class ContainerDefinition extends cdk.Construct { command: this.props.command, cpu: this.props.cpu, disableNetworking: this.props.disableNetworking, + dependsOn: cdk.Lazy.anyValue({ produce: () => renderArray(this.containerDependencies, renderContainerDependency) }), dnsSearchDomains: this.props.dnsSearchDomains, dnsServers: this.props.dnsServers, dockerLabels: this.props.dockerLabels, @@ -469,15 +488,15 @@ export class ContainerDefinition extends cdk.Construct { image: this.imageConfig.imageName, memory: this.props.memoryLimitMiB, memoryReservation: this.props.memoryReservationMiB, - mountPoints: this.mountPoints.map(renderMountPoint), - name: this.node.id, - portMappings: this.portMappings.map(renderPortMapping), + mountPoints: cdk.Lazy.anyValue({ produce: () => renderArray(this.mountPoints, renderMountPoint) }), + name: this.containerName, + portMappings: cdk.Lazy.anyValue({ produce: () => renderArray(this.portMappings, renderPortMapping) }), privileged: this.props.privileged, readonlyRootFilesystem: this.props.readonlyRootFilesystem, repositoryCredentials: this.imageConfig.repositoryCredentials, - ulimits: this.ulimits.map(renderUlimit), + ulimits: cdk.Lazy.anyValue({ produce: () => renderArray(this.ulimits, renderUlimit) }), user: this.props.user, - volumesFrom: this.volumesFrom.map(renderVolumeFrom), + volumesFrom: cdk.Lazy.anyValue({ produce: () => renderArray(this.volumesFrom, renderVolumeFrom) }), workingDirectory: this.props.workingDirectory, logConfiguration: this.logDriverConfig, environment: this.props.environment && renderKV(this.props.environment, 'name', 'value'), @@ -493,7 +512,7 @@ export class ContainerDefinition extends cdk.Construct { }), extraHosts: this.props.extraHosts && renderKV(this.props.extraHosts, 'hostname', 'ipAddress'), healthCheck: this.props.healthCheck && renderHealthCheck(this.props.healthCheck), - links: this.links, + links: cdk.Lazy.listValue({ produce: () => renderArray(this.links, l => l) }), linuxParameters: this.linuxParameters && this.linuxParameters.renderLinuxParameters(), }; } @@ -550,6 +569,13 @@ export interface HealthCheck { readonly timeout?: cdk.Duration; } +function renderArray(array: ReadonlyArray, render: (value: T1) => T2): T2[] | undefined { + if (array.length < 1) { + return undefined; + } + return array.map(render); +} + function renderKV(env: { [key: string]: string }, keyName: string, valueName: string): any { const ret = []; for (const [key, value] of Object.entries(env)) { @@ -640,6 +666,58 @@ function renderUlimit(ulimit: Ulimit): CfnTaskDefinition.UlimitProperty { hardLimit: ulimit.hardLimit, }; } +/** + * The details of a dependency on another container in the task definition. + * + * @see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDependency.html + */ +export interface ContainerDependency { + /** + * The container to depend on. + */ + readonly container: ContainerDefinition; + + /** + * The state the container needs to be in to satisfy the dependency and proceed with startup. + * Valid values are ContainerDependencyCondition.START, ContainerDependencyCondition.COMPLETE, + * ContainerDependencyCondition.SUCCESS and ContainerDependencyCondition.HEALTHY. + * + * @default ContainerDependencyCondition.HEALTHY + */ + readonly condition?: ContainerDependencyCondition; +} + +export enum ContainerDependencyCondition { + /** + * This condition emulates the behavior of links and volumes today. + * It validates that a dependent container is started before permitting other containers to start. + */ + START = 'START', + + /** + * This condition validates that a dependent container runs to completion (exits) before permitting other containers to start. + * This can be useful for nonessential containers that run a script and then exit. + */ + COMPLETE = 'COMPLETE', + + /** + * This condition is the same as COMPLETE, but it also requires that the container exits with a zero status. + */ + SUCCESS = 'SUCCESS', + + /** + * This condition validates that the dependent container passes its Docker health check before permitting other containers to start. + * This requires that the dependent container has health checks configured. This condition is confirmed only at task startup. + */ + HEALTHY = 'HEALTHY', +} + +function renderContainerDependency(containerDependency: ContainerDependency): CfnTaskDefinition.ContainerDependencyProperty { + return { + containerName: containerDependency.container.containerName, + condition: containerDependency.condition || ContainerDependencyCondition.HEALTHY + }; +} /** * Port mappings allow containers to access ports on the host container instance to send or receive traffic. diff --git a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts index 9b04a18eecebe..96cf8e57b5bfd 100644 --- a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts @@ -195,7 +195,7 @@ export class Ec2Service extends BaseService implements IEc2Service, elb.ILoadBal this.loadBalancers.push({ loadBalancerName: loadBalancer.loadBalancerName, - containerName: this.taskDefinition.defaultContainer!.node.id, + containerName: this.taskDefinition.defaultContainer!.containerName, containerPort: this.taskDefinition.defaultContainer!.containerPort, }); } diff --git a/packages/@aws-cdk/aws-ecs/lib/linux-parameters.ts b/packages/@aws-cdk/aws-ecs/lib/linux-parameters.ts index a58c8bba4fe5e..044734d148603 100644 --- a/packages/@aws-cdk/aws-ecs/lib/linux-parameters.ts +++ b/packages/@aws-cdk/aws-ecs/lib/linux-parameters.ts @@ -106,11 +106,11 @@ export class LinuxParameters extends cdk.Construct { initProcessEnabled: this.initProcessEnabled, sharedMemorySize: this.sharedMemorySize, capabilities: { - add: this.capAdd, - drop: this.capDrop, + add: cdk.Lazy.listValue({ produce: () => this.capAdd }), + drop: cdk.Lazy.listValue({ produce: () => this.capDrop }), }, - devices: this.devices.map(renderDevice), - tmpfs: this.tmpfs.map(renderTmpfs) + devices: cdk.Lazy.anyValue({ produce: () => this.devices.map(renderDevice) }), + tmpfs: cdk.Lazy.anyValue({ produce: () => this.tmpfs.map(renderTmpfs) }) }; } } diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.expected.json b/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.expected.json index 27a716eab42c5..04234cd5ddbfd 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.expected.json +++ b/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.expected.json @@ -820,18 +820,14 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "Memory": 256, - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Family": "awsecsintegTaskDef6FDFB69A", diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.expected.json b/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.expected.json index 599d4d566c8c7..533dc55691571 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.expected.json +++ b/packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.expected.json @@ -841,9 +841,7 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "Memory": 256, - "MountPoints": [], "Name": "web", "PortMappings": [ { @@ -851,9 +849,7 @@ "HostPort": 8080, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Family": "awsecsintegecsTaskDef8DD0C801", diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-awsvpc-nw.expected.json b/packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-awsvpc-nw.expected.json index e404d1fa015ac..252f04c6e85ff 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-awsvpc-nw.expected.json +++ b/packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-awsvpc-nw.expected.json @@ -829,9 +829,7 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "Memory": 256, - "MountPoints": [], "Name": "frontend", "PortMappings": [ { @@ -839,9 +837,7 @@ "HostPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Family": "awsecsintegecsTaskDef8DD0C801", diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-bridge-nw.expected.json b/packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-bridge-nw.expected.json index 3310f3c9bc329..3405d3006ead3 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-bridge-nw.expected.json +++ b/packages/@aws-cdk/aws-ecs/test/ec2/integ.sd-bridge-nw.expected.json @@ -829,9 +829,7 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], "Memory": 256, - "MountPoints": [], "Name": "frontend", "PortMappings": [ { @@ -839,9 +837,7 @@ "HostPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Family": "awsecsintegecsfrontendTD16AB905D", diff --git a/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-task-definition.ts b/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-task-definition.ts index 60e26c8b53e39..f2d827fe6c72d 100644 --- a/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-task-definition.ts @@ -69,8 +69,6 @@ export = { Essential: true, Memory: 512, Image: "amazon/amazon-ecs-sample", - Links: [], - MountPoints: [], Name: "web", PortMappings: [{ ContainerPort: 3000, @@ -82,7 +80,6 @@ export = { Name: "rss", SoftLimit: 128 }], - VolumesFrom: [] }], })); @@ -128,7 +125,132 @@ export = { test.done(); }, + "correctly sets container dependenices"(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); + + const dependency1 = taskDefinition.addContainer('dependency1', { + image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), + memoryLimitMiB: 512 + }); + + const dependency2 = taskDefinition.addContainer('dependency2', { + image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), + memoryLimitMiB: 512 + }); + const container = taskDefinition.addContainer("web", { + image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), + memoryLimitMiB: 512 + }); + + container.addContainerDependencies({ + container: dependency1 + }, + { + container: dependency2, + condition: ecs.ContainerDependencyCondition.SUCCESS + } + ); + + // THEN + expect(stack).to(haveResourceLike("AWS::ECS::TaskDefinition", { + Family: "Ec2TaskDef", + ContainerDefinitions: [{ + Name: "dependency1" + }, + { + Name: "dependency2" + }, + { + Name: "web", + DependsOn: [{ + Condition: "HEALTHY", + ContainerName: "dependency1" + }, + { + Condition: "SUCCESS", + ContainerName: "dependency2" + }] + }] + })); + + test.done(); + }, + "correctly sets links"(test: Test) { + const stack = new cdk.Stack(); + + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef', { + networkMode: ecs.NetworkMode.BRIDGE + }); + + const container = taskDefinition.addContainer("web", { + image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), + memoryLimitMiB: 512 + }); + + const linkedContainer1 = taskDefinition.addContainer("linked1", { + image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), + memoryLimitMiB: 512 + }); + + const linkedContainer2 = taskDefinition.addContainer("linked2", { + image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), + memoryLimitMiB: 512 + }); + + container.addLink(linkedContainer1, 'linked'); + container.addLink(linkedContainer2); + + // THEN + expect(stack).to(haveResourceLike("AWS::ECS::TaskDefinition", { + ContainerDefinitions: [{ + Links: [ + 'linked1:linked', + 'linked2' + ], + Name: "web" + }, + { + Name: 'linked1' + }, + { + Name: 'linked2' + }] + })); + + test.done(); + }, + "correctly sets volumes from"(test: Test) { + const stack = new cdk.Stack(); + + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef', {}); + + const container = taskDefinition.addContainer("web", { + image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), + memoryLimitMiB: 512 + }); + + container.addVolumesFrom({ + sourceContainer: "SourceContainer", + readOnly: true + }); + + // THEN + expect(stack).to(haveResourceLike("AWS::ECS::TaskDefinition", { + ContainerDefinitions: [{ + VolumesFrom: [ + { + SourceContainer: "SourceContainer", + ReadOnly: true, + } + ] + }] + })); + + test.done(); + }, "correctly sets volumes"(test: Test) { // GIVEN const stack = new cdk.Stack(); diff --git a/packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.expected.json b/packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.expected.json index 4cc54ebaaac04..9b6d06f47c9eb 100644 --- a/packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.expected.json +++ b/packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.expected.json @@ -380,17 +380,13 @@ { "Essential": true, "Image": "amazon/amazon-ecs-sample", - "Links": [], - "MountPoints": [], "Name": "web", "PortMappings": [ { "ContainerPort": 80, "Protocol": "tcp" } - ], - "Ulimits": [], - "VolumesFrom": [] + ] } ], "Cpu": "512", diff --git a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.expected.json b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.expected.json index b22e03b1e7723..bd446ad581462 100644 --- a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.expected.json +++ b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.expected.json @@ -768,7 +768,6 @@ ] ] }, - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -782,11 +781,7 @@ } }, "Memory": 256, - "MountPoints": [], - "Name": "TheContainer", - "PortMappings": [], - "Ulimits": [], - "VolumesFrom": [] + "Name": "TheContainer" } ], "ExecutionRoleArn": { diff --git a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.expected.json b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.expected.json index c4a85357a7070..305b0394cdc5c 100644 --- a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.expected.json +++ b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.expected.json @@ -331,7 +331,6 @@ ] ] }, - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -344,11 +343,7 @@ } } }, - "MountPoints": [], - "Name": "TheContainer", - "PortMappings": [], - "Ulimits": [], - "VolumesFrom": [] + "Name": "TheContainer" } ], "Cpu": "256", diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.expected.json index 63cbbe67ce751..9c8661f59b669 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.expected.json @@ -552,7 +552,6 @@ ] ] }, - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -564,11 +563,7 @@ } }, "Memory": 256, - "MountPoints": [], - "Name": "TheContainer", - "PortMappings": [], - "Ulimits": [], - "VolumesFrom": [] + "Name": "TheContainer" } ], "ExecutionRoleArn": { diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.expected.json index 65e5f44e40c30..ccc9d1c6d21cc 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.expected.json @@ -125,7 +125,6 @@ ] ] }, - "Links": [], "LogConfiguration": { "LogDriver": "awslogs", "Options": { @@ -137,11 +136,7 @@ } }, "Memory": 256, - "MountPoints": [], - "Name": "TheContainer", - "PortMappings": [], - "Ulimits": [], - "VolumesFrom": [] + "Name": "TheContainer" } ], "Cpu": "256", diff --git a/packages/decdk/test/__snapshots__/synth.test.js.snap b/packages/decdk/test/__snapshots__/synth.test.js.snap index 2716126dc4e75..ba747165501a3 100644 --- a/packages/decdk/test/__snapshots__/synth.test.js.snap +++ b/packages/decdk/test/__snapshots__/synth.test.js.snap @@ -619,13 +619,8 @@ Object { Object { "Essential": true, "Image": "redis", - "Links": Array [], "Memory": 1024, - "MountPoints": Array [], "Name": "ContainerDef", - "PortMappings": Array [], - "Ulimits": Array [], - "VolumesFrom": Array [], }, ], "Cpu": "1024",