Skip to content

Commit

Permalink
feat(ecs-patterns): add family name to load balanced service properti…
Browse files Browse the repository at this point in the history
…es (#4688)

* feat(ecs-patterns): add family name in taskImageOptions for load balanced services

* Add unit test
  • Loading branch information
piradeepk authored and mergify[bot] committed Oct 28, 2019
1 parent e17ba55 commit d7654e7
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ export interface ApplicationLoadBalancedTaskImageOptions {
* @default 80
*/
readonly containerPort?: number;

/**
* The name of a family that this task definition is registered to. A family groups multiple versions of a task definition.
*
* @default - Automatically generated name.
*/
readonly family?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ export interface NetworkLoadBalancedTaskImageOptions {
* @default 80
*/
readonly containerPort?: number;

/**
* The name of a family that this task definition is registered to. A family groups multiple versions of a task definition.
*
* @default - Automatically generated name.
*/
readonly family?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
const taskImageOptions = props.taskImageOptions;
this.taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {
executionRole: taskImageOptions.executionRole,
taskRole: taskImageOptions.taskRole
taskRole: taskImageOptions.taskRole,
family: taskImageOptions.family,
});

// Create log driver if logging is enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas
const taskImageOptions = props.taskImageOptions;
this.taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {
executionRole: taskImageOptions.executionRole,
taskRole: taskImageOptions.taskRole
taskRole: taskImageOptions.taskRole,
family: taskImageOptions.family,
});

// Create log driver if logging is enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu,
executionRole: taskImageOptions.executionRole,
taskRole: taskImageOptions.taskRole
taskRole: taskImageOptions.taskRole,
family: taskImageOptions.family,
});

// Create log driver if logging is enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu,
executionRole: taskImageOptions.executionRole,
taskRole: taskImageOptions.taskRole
taskRole: taskImageOptions.taskRole,
family: taskImageOptions.family,
});

// Create log driver if logging is enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, haveResourceLike, SynthUtils } from '@aws-cdk/assert';
import { expect, haveResource, haveResourceLike, SynthUtils } from '@aws-cdk/assert';
import ec2 = require('@aws-cdk/aws-ec2');
import ecs = require('@aws-cdk/aws-ecs');
import iam = require('@aws-cdk/aws-iam');
Expand Down Expand Up @@ -202,4 +202,57 @@ export = {
test.done();
},

'test load balanced service with family defined'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });

// WHEN
new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("/aws/aws-example-app"),
enableLogging: false,
environment: {
TEST_ENVIRONMENT_VARIABLE1: "test environment variable 1 value",
TEST_ENVIRONMENT_VARIABLE2: "test environment variable 2 value"
},
family: "fargate-task-family",
},
desiredCount: 2,
memoryLimitMiB: 512,
serviceName: "fargate-test-service",
});

// THEN
expect(stack).to(haveResource("AWS::ECS::Service", {
DesiredCount: 2,
LaunchType: "FARGATE",
ServiceName: "fargate-test-service"
}));

expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
{
Environment: [
{
Name: "TEST_ENVIRONMENT_VARIABLE1",
Value: "test environment variable 1 value"
},
{
Name: "TEST_ENVIRONMENT_VARIABLE2",
Value: "test environment variable 2 value"
}
],
Image: "/aws/aws-example-app",
}
],
Family: "fargate-task-family"
}));

test.done();
},

};

0 comments on commit d7654e7

Please sign in to comment.