Skip to content

Elastic Beanstalk: add custom ELBv2 rules through configuration options

0

Hi AWS community.

I manage an Elastic Beanstalk (EB) setup with Terraform. The setup contains an Application Load Balancer (LB). I selected a dedicated LB (LoadBalancerIsShared=false), so that EB creates and manages the LB.

I'm now required to add custom Listener rules, for example a fixed-response and a few redirects.

Unfortunately, I can't figure out how to add these through the configuration options and without manually using the Management Console. I can create a custom rule by applying the following options. For example:

Namespace: "aws:elbv2:listenerrule:foobar"
Name: "HostHeaders"
Value: "*.example.com"
Namespace: "aws:elbv2:listener:80"
Name: "Rules"
Value: "foobar"

How can I define an action such as "fixed-response" and the behavior of that action (HTML response code and text)? The documentation did not help.

I'd like to avoid the fallback option and create my own load balancer outside of EB. Although this sounds conceivable, I'd prefer to let EB take care of the LB if possible.

Thanks for any help. Yarpen

1 Answer
0

There is no EB configuration option that allows you to specify fixed-response listener rules. What you can do instead is use EB's built-in functionality to add resource to the generated Cloudformation template to add a customer listener rule to your ALB with the desired fixed-response configuration. This is accomplished by creating a configuration file in the .ebextensions directory using the Resources key. You will need to find the CloudFormation resource name of the listener you wish to reference to add the rule. In the example below, it is AWSEBV2LoadBalancerListener443.

Example configuration file (.ebextensions/fixedResponse.config):

Resources:
  fixedResponse404Listener:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Properties:
      Actions:
        - Type: fixed-response
          FixedResponseConfig:
            StatusCode: 200
            ContentType: "application/json"
            MessageBody: "{ \"hello\": \"world\"}"
      Conditions: 
        - Field: path-pattern
          PathPatternConfig:
            Values: 
              - "/my/fixed/response"
      ListenerArn: { "Ref" : "AWSEBV2LoadBalancerListener443" }
      Priority: 40000

Relevant documentation:

AWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.