Skip to main content

Elastic Beanstalk HTTP to HTTPS redirection

·2 mins

I had trouble setting up CodeDeploy to work with Elastic Beanstalk, as I couldn’t get HTTP to redirect to HTTPS after trying all sorts of configurations. It ended up being a lot simpler than I thought it was, so here’s how to set it up.

Creating the Environment #

After you create the ELB application, go ahead and setup your first environment. After setting up your initial configuration options, go and click on Configure more options.

When the new page loads, go and click on Custom Configuration.
From there, you’ll be able to select a Load Balancer option below.

Customizing the Application Load Balancer #

We need to set the load balancer to use HTTPS. Click on Add Listener and then select a certificate you made with the Certificate Manager. This will create a single Target Group in EC2 to health check on port 80. You’ll also have created a single Load Balancer within EC2 as well.

Redirecting HTTP to HTTPS #

Go to your EC2 dashboard and go to the Load Balancer section. Select your newly created load balancer for HTTP and click on Edit.

Delete the action that is already selected, and then add an action to redirect. Update the port to 443, and then click on the checkmark. Go ahead and update the listeners.

DNS #

Copy the A record that is in your load balancer’s description, and then make a CNAME record in your DNS provider. Wait for it to propagate and then go to your hostname. Once that’s complete, if you go to the domain name at HTTP, it should automatically redirect to HTTPS.