ApplicationLoadBalancedFargateService: specify private subnets where the ALB will be deployed in
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
To have the option of manually selecting subnets for the ALB to be deployed in.
ApplicationLoadBalancedFargateService has this feature for tasks (taskSubnets) but not the ALB.
Allowing ApplicationLoadBalancedFargateService to automatically deploy an ALB based on the vpc/cluster defined in the construct works only when the VPC has few subnets (in my case 2 private subnets in different AZs) but doesn't work when you have multiple private subnets spread across multiple AZs hence returning the error below;
"A load balancer cannot be attached to multiple subnets in the same Availability Zone (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: InvalidConfigurationRequest; Request ID: 67912baa-9955-455c-bdbb-f42870fc467e; Proxy: null)"
### Use Case
Fargate tasks are to be created in private subnet A (eu-west-2a) and private subnet B (eu-west-2b) hence require the
created ALB to be associated with private subnet A (eu-west-2a) and private subnet B (eu-west-2b).
### Proposed Solution
Set ApplicationLoadBalancedFargateService so that it should either;
a. automatically assume the subnets selected in taskSubnets
or
b. add an "ALB subnets" option that allows the a user to select the subnets similar to what we currenetly have for taskSubnets.
const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
cluster,
taskDefinition,
desiredCount: 2,
taskSubnets:{
subnets:[
ec2.Subnet.fromSubnetAttributes(this, 'subnet-12345678aa', {
subnetId: 'subnet-12345678aa', availabilityZone: 'eu-west-2a', routeTableId:'rtb-0001234'
}),
ec2.Subnet.fromSubnetAttributes(this, 'subnet-12345678bb', {
subnetId: 'subnet-12345678bb', availabilityZone: 'eu-west-2b', routeTableId:'rtb-000567'
}),
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.28.0
### Environment details (OS name and version, etc.)
macOS version 12.4
Contributor guide
Research direction
Start at the ApplicationLoadBalancedFargateService construct and compare its taskSubnets configuration with how the ALB subnets are selected. Reproduce the reported case with private subnets in eu-west-2a and eu-west-2b plus additional private subnets, then verify that users can select the ALB subnets and that the resulting load balancer has at most one subnet per Availability Zone.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100