Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ecs): 'desiredCount' and 'ephemeralStorageGiB' cannot be tokens #19453

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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