Skip to content

Commit

Permalink
fix(ecs): 'desiredCount' and 'ephemeralStorageGiB' cannot be tokens (#…
Browse files Browse the repository at this point in the history
…19453)

fixes #16648


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
peterwoodworth authored Apr 5, 2022
1 parent 053d22c commit c852239
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export abstract class ApplicationLoadBalancedServiceBase extends CoreConstruct {
}
this.cluster = props.cluster || this.getDefaultCluster(this, props.vpc);

if (props.desiredCount !== undefined && props.desiredCount < 1) {
if (props.desiredCount !== undefined && !cdk.Token.isUnresolved(props.desiredCount) && props.desiredCount < 1) {
throw new Error('You must specify a desiredCount greater than 0');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,3 +1047,29 @@ test('test Network load balanced service with docker labels defined', () => {
],
});
});

test('Passing in token for desiredCount will not throw error', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
const param = new cdk.CfnParameter(stack, 'prammm', {
type: 'Number',
default: 1,
});

// WHEN
const service = new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('/aws/aws-example-app'),
dockerLabels: { label1: 'labelValue1', label2: 'labelValue2' },
},
desiredCount: param.valueAsNumber,
});

// THEN
expect(() => {
service.internalDesiredCount;
}).toBeTruthy;
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tokenization } from '@aws-cdk/core';
import { Tokenization, Token } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { ImportedTaskDefinition } from '../base/_imported-task-definition';
import {
Expand Down Expand Up @@ -140,7 +140,8 @@ export class FargateTaskDefinition extends TaskDefinition implements IFargateTas
networkMode: NetworkMode.AWS_VPC,
});

if (props.ephemeralStorageGiB && (props.ephemeralStorageGiB < 21 || props.ephemeralStorageGiB > 200)) {
// eslint-disable-next-line max-len
if (props.ephemeralStorageGiB && !Token.isUnresolved(props.ephemeralStorageGiB) && (props.ephemeralStorageGiB < 21 || props.ephemeralStorageGiB > 200)) {
throw new Error('Ephemeral storage size must be between 21GiB and 200GiB');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ describe('fargate task definition', () => {
'Add the \'taskRole\' in ImportedTaskDefinitionProps to instantiate ImportedTaskDefinition');
});

test('Passing in token for ephemeral storage will not throw error', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const param = new cdk.CfnParameter(stack, 'prammm', {
type: 'Number',
default: 1,
});

const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef', {
ephemeralStorageGiB: param.valueAsNumber,
});

// THEN
expect(() => {
taskDefinition.ephemeralStorageGiB;
}).toBeTruthy;
});

test('runtime testing for windows container', () => {
// GIVEN
Expand Down

0 comments on commit c852239

Please sign in to comment.