I was confused by all the documentation and answers providing code for rewrite rules, which I could never get to work. I eventually figured out how to do this via the AWS web console:
Make sure you are using an Application Load Balancer for your application's environment.
Add a listener for https, port 443, and your certificate (AWS documentation covers this quite well)
This was the part that took me hours to figure out:
You cannot configure the redirect from Elastic Beanstalk's load balancer configuration section. You have to go to Services -> EC2 -> Load balancers
and then select the load balancer created for your application/environment.
If you have multiple load balancers, it's hard to determine which one is the correct one. I had to refer to the "Created At" timestamp to know which one to select.
Click the "Listeners" tab
- Click the View/edit rules link on the HTTP:80 listener
- Click the + icon to add a new rule
- Add an action of "Redirect to..." and enter 443 for the port.
The rest of the inputs defaulted to the correct values.
- Add a "Host header" condition and set the value to your host
- Save the rule