'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?



Solution 1:[1]

I ran into this issue as well, and from testing it appears that these .ebextensions /application-load-balancer.config settings only work if you create the environment with High Availability specified. So you can't just select the platform and upload your code and have the application load balancer and High Availability setup configured from the .config settings (even though the docs make it seem like this should work). Instead you must select the desired platform (PHP, etc.), upload your initial code, and then click on More Options and select the configuration preset for "High Availability". You may also need to select your VPC at this point as well, if you are deploying into a custom VPC network. You don't need to set any other settings, as those will be applied from your application-load-balancer.config file (and other .config files). It just seems that there's a distinction between environment creation and environment config, and some of these values can only be set during the "creation" step.

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ian
Solution 2 Ignat Sachivko