How can I create additional listeners for Elastic Beanstalk environments that use a shared load balancer?

2 minute read
0

I want to create additional listeners for AWS Elastic Beanstalk environments that use a shared load balancer.

Short description

If you use a shared load balancer with Elastic Beanstalk, then you can't use the aws:elbv2:listener:listener_port option or the Elastic Beanstalk console to create additional listeners. This is because Elastic Beanstalk doesn't manage the load balancer.

To create additional listeners for an Elastic Beanstalk environment with a shared load balancer, use .ebextension custom resources.

Note: It's a best practice to associate additional listeners with the lifecycle of the environment, and remove the listeners when you terminate the environment.

Resolution

1.     Create an Application Load Balancer that includes a default listener and target group.

2.    Create a YAML configuration file called additional-listener.config:

Resources:  AdditionalHttpListener: 
      Type: AWS::ElasticLoadBalancingV2::Listener 
	  Properties: 
        LoadBalancerArn: 
          "Fn::GetOptionSetting": 
		    Namespace: "aws:elbv2:loadbalancer"
            OptionName: "SharedLoadBalancer"
        DefaultActions: 
        - Type: forward 
		  TargetGroupArn: 
            Ref: AWSEBV2LoadBalancerTargetGroup 
        Port: 8080 
        Protocol: HTTP

Note: The preceding YAML configuration file follows the AWS CloudFormation specification for the AWS::ElasticLoadBalancingV2::Listener resource.

3.    Add the configuration file to the .ebextensions folder that's part of your application source bundle.

4.    Create a .zip file of your updated application source bundle.

5.    To create a new Elastic Beanstalk environment, use the .zip file. Or, update an existing environment that's configured with the shared load balancer from the previous step.

The configuration file creates an HTTP listener on port 8080 for the shared load balancer that's associated with your Elastic Beanstalk environment. Then, the listener forwards all traffic to the default process. To add rules to the listener, use the AWS::ElasticLoadBalancingV2::ListenerRule resource definition to extend the configuration file. Because the listener is an additional resource to the Elastic Beanstalk environment, the listener is removed if the environment is terminated. For more information, see Configuring a shared Application Load Balancer.

AWS OFFICIAL
AWS OFFICIALUpdated 8 months ago