Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect HTTP to HTTPS for Application Loadbalancer in Elastic Beanstalk in Cloudformation

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?

like image 756
DenCowboy Avatar asked Jun 28 '26 16:06

DenCowboy


1 Answers

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

like image 152
Chris Pollard Avatar answered Jun 30 '26 05:06

Chris Pollard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!