4

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?

johnnyodonnell
  • 1,838
  • 3
  • 16
  • 34
  • Can you try creating a default listener as described [here](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-elbv2-listener-default) in addition to specifying the kind of load balancer? – progfan Feb 07 '18 at 04:51
  • How are you verifying that "Elastic Beanstalk still creates a classic load balancer"? The settings you have seem to be working for me, but there does not appear to be an explicit confirmation for `LoadBalancerType ` on the EB Configuration screen in the AWS Console. – Dem Pilafian Mar 24 '18 at 19:04
  • @DemPilafian when I checked the EC2 page, it showed my load balancer was still classic – johnnyodonnell Mar 26 '18 at 16:06
  • The EB "Networking Tier" section normally shows a box for "Load Balancing", but it is not there with the `LoadBalancerType: application` setting (yet the EC2 page still displays `classic`... interesting). – Dem Pilafian Mar 27 '18 at 23:43

2 Answers2

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.

Ian
  • 146
  • 1
  • 6
1

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

Ignat Sachivko
  • 314
  • 2
  • 9