Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to configure an Application Load Balancer with Elastic Beanstalk ebextensions?

The Elastic Beanstalk documentation mentions that the load balancer type can be set with a config file in the .ebextensions folder. However, when I deploy my application in a newly created environment, Elastic Beanstalk still creates a classic load balancer.

I am creating the new environment through the AWS console and my application source package has the .ebextensions folder with settings specifying an application load balancer. As seen below:

.ebextensions/application-load-balancer.config

option_settings:
  aws:elasticbeanstalk:environment:
    LoadBalancerType: application

Am I missing a step during the creation of the environment? Have other people ran into this issue?

like image 221
johnnyodonnell Avatar asked Oct 12 '25 09:10

johnnyodonnell


1 Answers

I wonder why this question is so poorly documented and it is hard to find an answer or sample, even though extensions under .ebextensions folder seem be a convenient way to work with environments within CI/CD process.

The proper way how to get 'application' load balancer created in Elastic Beansltalk environment is to use AWS::ElasticLoadBalancingV2::LoadBalancer inside your .config file specifying resources.
Sample:

Resources:
  AWSEBV2LoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Scheme: internet-facing

AWS::ElasticLoadBalancingV2::LoadBalancer specification:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-loadbalancer.html
The specification says that it is possible to set 'network' or 'gateway' load balancers as "Type" property, in turn, the other doc (https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-alb.html) says that it is not possible and you should use aws:elasticbeanstalk:environment option inside the options file configuration. Whatever is true, the sample above works perfectly fine for 'application' load balancer since 'application' is the default type for V2.

Please note, that if you use ElasticLoadBalancingV2 load balancer, then you also have to use V2 listeners, target groups etc., as well as, V2 options (e.g. aws:elbv2:loadbalancer) inside your options configuration file

Sample for V2 listeners: https://github.com/awsdocs/elastic-beanstalk-samples/blob/b5e8eaea6a0acca6b80281d4f1afe408a50e1afb/configuration-files/aws-provided/resource-configuration/alb-http-to-https-redirection-full.config

like image 151
Ignat Sachivko Avatar answered Oct 13 '25 23:10

Ignat Sachivko