Skip to content

Commit

Permalink
feat(aws-ecs): Add desired count to LoadBalanced[Fargate|EC2]Service (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
clareliguori authored and rix0rrr committed Nov 8, 2018
1 parent e404316 commit cafcc11
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ obtained from either DockerHub or from ECR repositories:
DockerHub.
* `ecs.ContaienrImage.fromEcrRepository(repo, tag)`: use the given ECR repository as the image
to start.
* `ecs.ContainerImage.fromAsset({ directory: './image' })`: build and upload an
* `ecs.ContainerImage.fromAsset(this, 'Image', { directory: './image' })`: build and upload an
image directly from a `Dockerfile` in your source directory.

### Service
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export interface LoadBalancedEc2ServiceProps {
* @default true
*/
publicLoadBalancer?: boolean;

/**
* Number of desired copies of running tasks
*
* @default 1
*/
desiredCount?: number;
}

/**
Expand Down Expand Up @@ -81,6 +88,7 @@ export class LoadBalancedEc2Service extends cdk.Construct {

const service = new Ec2Service(this, "Service", {
cluster: props.cluster,
desiredCount: props.desiredCount || 1,
taskDefinition,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export interface LoadBalancedFargateServiceAppletProps extends cdk.StackProps {
* @default false
*/
publicTasks?: boolean;

/**
* Number of desired copies of running tasks
*
* @default 1
*/
desiredCount?: number;
}

/**
Expand All @@ -91,6 +98,7 @@ export class LoadBalancedFargateServiceApplet extends cdk.Stack {
publicLoadBalancer: props.publicLoadBalancer,
publicTasks: props.publicTasks,
image: DockerHub.image(props.image),
desiredCount: props.desiredCount,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export interface LoadBalancedFargateServiceProps {
* @default false
*/
publicTasks?: boolean;

/**
* Number of desired copies of running tasks
*
* @default 1
*/
desiredCount?: number;
}

/**
Expand Down Expand Up @@ -103,6 +110,7 @@ export class LoadBalancedFargateService extends cdk.Construct {
const assignPublicIp = props.publicTasks !== undefined ? props.publicTasks : false;
const service = new FargateService(this, "Service", {
cluster: props.cluster,
desiredCount: props.desiredCount || 1,
taskDefinition,
assignPublicIp
});
Expand Down
39 changes: 35 additions & 4 deletions packages/@aws-cdk/aws-ecs/test/test.l3s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ export = {
new ecs.LoadBalancedEc2Service(stack, 'Service', {
cluster,
memoryLimitMiB: 1024,
image: ecs.DockerHub.image('test')
image: ecs.DockerHub.image('test'),
desiredCount: 2
});

// THEN - stack containers a load balancer
// THEN - stack containers a load balancer and a service
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer'));

expect(stack).to(haveResource("AWS::ECS::Service", {
DesiredCount: 2,
LaunchType: "EC2",
}));

test.done();
},

Expand All @@ -34,12 +40,37 @@ export = {
// WHEN
new ecs.LoadBalancedFargateService(stack, 'Service', {
cluster,
image: ecs.DockerHub.image('test')
image: ecs.DockerHub.image('test'),
desiredCount: 2
});

// THEN - stack containers a load balancer
// THEN - stack contains a load balancer and a service
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer'));

expect(stack).to(haveResource("AWS::ECS::Service", {
DesiredCount: 2,
LaunchType: "FARGATE",
}));

test.done();
},

'test Fargateloadbalanced applet'(test: Test) {
// WHEN
const app = new cdk.App();
const stack = new ecs.LoadBalancedFargateServiceApplet(app, 'Service', {
image: 'test',
desiredCount: 2
});

// THEN - stack contains a load balancer and a service
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer'));

expect(stack).to(haveResource("AWS::ECS::Service", {
DesiredCount: 2,
LaunchType: "FARGATE",
}));

test.done();
}
};

0 comments on commit cafcc11

Please sign in to comment.