Skip to content

Commit

Permalink
feat(ecs-patterns): higher-level constructs for ECS service with mult…
Browse files Browse the repository at this point in the history
…iple target groups (#5083)

* First draft for MTG higher-level constructs

* Add examples in README

* Docstring fix and minor code refactoring

* Minor fix for import without using require
  • Loading branch information
iamhopaul123 authored and mergify[bot] committed Dec 18, 2019
1 parent a4245d9 commit c0a7192
Show file tree
Hide file tree
Showing 18 changed files with 5,887 additions and 8 deletions.
139 changes: 136 additions & 3 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This library provides higher-level Amazon ECS constructs which follow common arc

## Application Load Balanced Services

To define an Amazon ECS service that is behind an application load balancer, instantiate one of the following:
To define an Amazon ECS service that is behind an application load balancer, instantiate one of the following:

* `ApplicationLoadBalancedEc2Service`

Expand Down Expand Up @@ -51,14 +51,63 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat
});
```

Instead of providing a cluster you can specify a VPC and CDK will create a new ECS cluster.
Instead of providing a cluster you can specify a VPC and CDK will create a new ECS cluster.
If you deploy multiple services CDK will only create one cluster per VPC.

You can omit `cluster` and `vpc` to let CDK create a new VPC with two AZs and create a cluster inside this VPC.

Additionally, if more than one application target group are needed, instantiate one of the following:

* `ApplicationMultipleTargetGroupsEc2Service`

```ts
// One application load balancer with one listener and two target groups.
const loadBalancedEc2Service = new ApplicationMultipleTargetGroupsEc2Service(stack, 'Service', {
cluster,
memoryLimitMiB: 256,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
targetGroups: [
{
containerPort: 80,
},
{
containerPort: 90,
pathPattern: 'a/b/c',
priority: 10
}
]
});
```

* `ApplicationMultipleTargetGroupsFargateService`

```ts
// One application load balancer with one listener and two target groups.
const loadBalancedFargateService = new ApplicationMultipleTargetGroupsFargateService(stack, 'Service', {
cluster,
memoryLimitMiB: 1024,
cpu: 512,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
targetGroups: [
{
containerPort: 80,
},
{
containerPort: 90,
pathPattern: 'a/b/c',
priority: 10
}
]
});
```

## Network Load Balanced Services

To define an Amazon ECS service that is behind a network load balancer, instantiate one of the following:
To define an Amazon ECS service that is behind a network load balancer, instantiate one of the following:

* `NetworkLoadBalancedEc2Service`

Expand Down Expand Up @@ -94,6 +143,90 @@ The CDK will create a new Amazon ECS cluster if you specify a VPC and omit `clus

If `cluster` and `vpc` are omitted, the CDK creates a new VPC with subnets in two Availability Zones and a cluster within this VPC.

Additionally, if more than one network target group is needed, instantiate one of the following:

* NetworkMultipleTargetGroupsEc2Service

```ts
// Two network load balancers, each with their own listener and target group.
const loadBalancedEc2Service = new NetworkMultipleTargetGroupsEc2Service(stack, 'Service', {
cluster,
memoryLimitMiB: 256,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
loadBalancers: [
{
name: 'lb1',
listeners: [
{
name: 'listener1'
}
]
},
{
name: 'lb2',
listeners: [
{
name: 'listener2'
}
]
}
],
targetGroups: [
{
containerPort: 80,
listener: 'listener1'
},
{
containerPort: 90,
listener: 'listener2'
}
]
});
```

* NetworkMultipleTargetGroupsFargateService

```ts
// Two network load balancers, each with their own listener and target group.
const loadBalancedFargateService = new NetworkMultipleTargetGroupsFargateService(stack, 'Service', {
cluster,
memoryLimitMiB: 512,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
loadBalancers: [
{
name: 'lb1',
listeners: [
{
name: 'listener1'
}
]
},
{
name: 'lb2',
listeners: [
{
name: 'listener2'
}
]
}
],
targetGroups: [
{
containerPort: 80,
listener: 'listener1'
},
{
containerPort: 90,
listener: 'listener2'
}
]
});
```

## Queue Processing Services

To define a service that creates a queue and reads from that queue, instantiate one of the following:
Expand Down
Loading

0 comments on commit c0a7192

Please sign in to comment.