diff --git a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts index cda7dd406e156..3d1403beb949a 100644 --- a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts @@ -478,7 +478,7 @@ function getHealthCheckCommand(hc: HealthCheck): string[] { return hcCommand; } - if (cmd[0] !== "CMD" || cmd[0] !== 'CMD-SHELL') { + if (cmd[0] !== "CMD" && cmd[0] !== 'CMD-SHELL') { hcCommand.push('CMD'); } diff --git a/packages/@aws-cdk/aws-ecs/test/test.container-definition.ts b/packages/@aws-cdk/aws-ecs/test/test.container-definition.ts index fc88979637a90..983e908d8d7f3 100644 --- a/packages/@aws-cdk/aws-ecs/test/test.container-definition.ts +++ b/packages/@aws-cdk/aws-ecs/test/test.container-definition.ts @@ -360,7 +360,7 @@ export = { test.done(); }, - 'can specify Health Check values'(test: Test) { + 'can specify Health Check values in shell form'(test: Test) { // GIVEN const stack = new cdk.Stack(); const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef'); @@ -396,6 +396,78 @@ export = { test.done(); }, + 'can specify Health Check values in array form starting with CMD-SHELL'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef'); + const hcCommand = "curl localhost:8000"; + + // WHEN + taskDefinition.addContainer('cont', { + image: ecs.ContainerImage.fromRegistry('test'), + memoryLimitMiB: 1024, + healthCheck: { + command: ["CMD-SHELL", hcCommand], + intervalSeconds: 20, + retries: 5, + startPeriod: 10 + } + }); + + // THEN + expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + HealthCheck: { + Command: ["CMD-SHELL", hcCommand], + Interval: 20, + Retries: 5, + Timeout: 5, + StartPeriod: 10 + }, + } + ] + })); + + test.done(); + }, + + 'can specify Health Check values in array form starting with CMD'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef'); + const hcCommand = "curl localhost:8000"; + + // WHEN + taskDefinition.addContainer('cont', { + image: ecs.ContainerImage.fromRegistry('test'), + memoryLimitMiB: 1024, + healthCheck: { + command: ["CMD", hcCommand], + intervalSeconds: 20, + retries: 5, + startPeriod: 10 + } + }); + + // THEN + expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + HealthCheck: { + Command: ["CMD", hcCommand], + Interval: 20, + Retries: 5, + Timeout: 5, + StartPeriod: 10 + }, + } + ] + })); + + test.done(); + }, + 'can specify private registry credentials'(test: Test) { // GIVEN const stack = new cdk.Stack();