Search code examples
amazon-web-servicesamazon-elastic-beanstalkamazon-elbebextensions

Elastic Beanstalk instances not being attached to custom load balancer


I have an Elastic Beanstalk instance with the following .ebextensions config file to setup a custom load balancer.

Resources:
  ApiLoadBalancer:
    Type: AWS::ElasticLoadBalancing::LoadBalancer
    Properties:
      ConnectionSettings:
         IdleTimeout: 900
      Listeners:
      - InstancePort: '80'
        InstanceProtocol: 'HTTP'
        LoadBalancerPort: '443'
        Protocol: 'HTTPS'
        SSLCertificateId: 'certificate-id'
      HealthCheck:
         HealthyThreshold: '3'
         Interval: '30'
         Target: 'HTTP:80/api/healthcheck'
         Timeout: '5'
         UnhealthyThreshold: '5'
      AvailabilityZones:
      - "us-east-1a"

However, whenever the beanstalk environment is rebuilt, my custom load balancer is created as defined, however the EC2 instances themselves are not attached to it.

How do I get the instances to use my custom load balancer?


Solution

  • You need to configure elastic beanstalk load balancer via elastic beanstalk namespaces. Instead of setting up the whole new load balancer via Type: AWS::ElasticLoadBalancing::LoadBalancer, you should specify your load balancer configuration in this way (assuming that you want to use Classic Load Balancer, based on the posted configuration).

    option_settings:
      aws:elb:listener:443:
        ListenerProtocol: HTTPS
        SSLCertificateId: arn:aws:acm:us-east-2:123456789012:certificate/12345678-12ab-34cd-56ef-12345678
        InstancePort: 80
        InstanceProtocol: HTTP
      aws:elb:listener:
        ListenerEnabled: false