[ecs-patterns]: allow use of existing load balancer in ApplicationMultipleTargetGroupsEc2Service
See original GitHub issueThis is a 🚀 Feature Request
Description
Would like to be able to use an existing load balancer with ApplicationMultipleTargetGroupsEc2Service.
Load balancer pricing includes a fee per hour of load balancer running, which currently means about $18 per month. Running many services, each with its own balancer, can quickly add up.
Additionally, creating a separate load balancer for each service means we can’t run multiple services under the same DNS name. So it’s not possible to call different microservices depending on the path, for example (probably a common pattern?). Or group multiple subdomains on the same load balancer.
Use Case
const service1 = new ApplicationMultipleTargetGroupsEc2Service(this, "Service1",{
...
targetGroups: [
{
containerPort: 80,
listener: "listener",
**pathPattern: "service1",**
priority: 1,
protocol: Protocol.TCP,
},
});
const service2 = new ApplicationMultipleTargetGroupsEc2Service(this, "Service2",{
targetGroups: [
{
containerPort: 80,
listener: "listener",
**pathPattern: "service2",**
priority: 2,
protocol: Protocol.TCP,
},
});
I would like that that two gets deployed to (Use the same LoadBalancer, instead of creating one for Each Service):
- myalb.amazonaws.com/service1
- myalb.amazonaws.com/service2
Proposed Solution
Not have a workaround. Would need to skip ECS Patterns for this.
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:5 (2 by maintainers)
Top GitHub Comments
@ggallotti If you use 1 port to 1 service,
ApplicationMultipleTargetGroupsEc2Service
doesn’t look like the way to go as you would need only one target group per service. From what I learned, ECS Patterns are suitable for fairly generic needs and doesn’t support usage of existing resources like load balancers.To use an existing ALB, I would recommend to import its listener and use the
Ec2Service
class . You can create many services with many target groups and linked them to one listener.Here an example to attach one service to one target group to an existing listener:
Of course, I would be interested if someone is aware of a more concise approach.
Thanks for the code @poupougnac. Seems very simple and clean. Yes, I think that for now I would need to Skip ECS Patterns for this.