- Newest
- Most votes
- Most comments
The missing namespace option is
{
namespace: 'aws:elasticbeanstalk:environment',
optionName: 'LoadBalancerIsShared',
value: 'true',
},
Full config for shared beanstalk ALB should look something like this.
{
namespace: 'aws:elasticbeanstalk:environment',
optionName: 'LoadBalancerType',
value: 'application',
},
{
namespace: 'aws:elasticbeanstalk:environment',
optionName: 'LoadBalancerIsShared',
value: 'true',
},
{
namespace: 'aws:ec2:vpc',
optionName: 'ELBSubnets',
value: publicSubnets,
},
{
namespace: 'aws:elbv2:loadbalancer',
optionName: 'SharedLoadBalancer',
value: props.sharedAlbArn,
},
answered a year ago
To use a shared Application Load Balancer with multiple Elastic Beanstalk environments, you need to configure the environment with the correct option settings in AWS CDK.
The shared Application Load Balancer feature was introduced by AWS Elastic Beanstalk in September 2020 to help save costs when you have multiple environments, such as in microservice architectures. Instead of each environment having its own dedicated load balancer, you can create and manage a load balancer yourself using Amazon EC2 and then share it across multiple Elastic Beanstalk environments.
In AWS CDK, you can configure a shared Application Load Balancer for an Elastic Beanstalk environment using the following option settings:
{ namespace: "aws:elbv2:loadbalancer", optionName: "SharedLoadBalancer", value: "arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/app/MySharedALB/e574ea4c37ad2ec8" }
You must also set the load balancer type to "application" in your environment configuration:
{ namespace: "aws:elasticbeanstalk:environment", optionName: "LoadBalancerType", value: "application" }
Important requirements to note:
- Your environment must be in a VPC with subnets in at least two Availability Zones to use an Application Load Balancer.
- You need to create the shared Application Load Balancer first using Amazon EC2 before referencing it in your Elastic Beanstalk environments.
- When using a shared load balancer, you are responsible for creating and managing the load balancer, listeners, and listener rules, while Elastic Beanstalk manages the processes (target groups).
If you're encountering errors with the configuration, ensure that:
- You've correctly specified the ARN of an existing Application Load Balancer
- You've set the load balancer type to "application"
- You're not trying to configure listener ARNs directly (as this isn't supported)
The shared load balancer approach is specifically designed for cost savings in scenarios with multiple environments, such as microservice architectures, where having dedicated load balancers for each environment would be costly.
Sources
Configuring a shared Application Load Balancer - AWS Elastic Beanstalk
eb create - AWS Elastic Beanstalk
Release: Elastic Beanstalk introduces shared Application Load Balancers on September 10, 2020 - AWS Elastic Beanstalk
Load balancer for your Elastic Beanstalk environment - AWS Elastic Beanstalk

but this still results in the stack creating new ALB's