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

feat(aws-ecs): Add desired count to LoadBalanced[Fargate|EC2]Service #1111

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
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();
}
};