6

I'm using an ALB in my Elastic Beanstalk environment. It works (on 80 and 443) but I want to implement a redirect rule in the cloudformation template.

I was able to create the rule in the console:

If PATH is / Redirect to HTTPS://#{host}:443/app?#{query}

How can I do this for an ALB in Elastic Beanstalk in CloudFormation?

DenCowboy
  • 13,884
  • 38
  • 114
  • 210

1 Answers1

6

You can add an EB extension that is a cloudformation snippet. It would look something like this:

albRedirect:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    DefaultActions:
      - Type: redirect
        RedirectConfig:
          Protocol: HTTPS
          Host: '#{host}'
          Query: '#{query}'
          Path: '/#{path}'
          Port: '443'
          StatusCode: HTTP_301
    LoadBalancerArn: !Ref AWSEBV2LoadBalancer
    Port: 80
    Protocol: HTTP

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-resources.html

Chris Pollard
  • 1,625
  • 8
  • 11