For this gist I assume you are working with an Elastic Beanstalk Application Environment set up with an Application Load Balancer. I also assume you are wanting to point a subdomain of your custom domain to your EB application. If you have a different setup then this process may not work for you, though there may still be some useful parts. As with most guides on the internet, your mileage may vary.
- A running application environment in Elastic Beanstalk
- Access to modify the DNS records on your custom domain
- Access to AWS Console with the relevant IAM permissions
Navigate to the DNS Records manager for your domain and add a new CNAME record:
- Set the "host" to your chosen subdomain (i.e, for "login.example.com", it would be "login")
- Set the "value" to your current Elastic Beanstalk's Application Environment domain, for example: "login.eba-xxxyyyzz.us-east-2.elasticbeanstalk.com" (you can find this in the "Environment overview" panel in Elastic Beanstalk)
- Set the "TTL" to "1 min" and save
Once the record has been processed, going to http://login.example.com, should show your elastic beanstalk application. It can take a while before the DNS record has processed so you’ll need to be patient.
At this point you will only be able to access your application on the unsecure "HTTP" protocol. Continue with this guide to be able to serve your application securely over "HTTPS".
In AWS, navigate to the AWS Certificate Manager (ACM)
- Click "Request" to create a new certificate
- Select "Request a public certificate" and click Next
- Enter the fully qualified domain name, for example "login.example.com"
- Select "DNS validation" as the validation method
- Leave "Key algorithm" as the default
- Set any tags if you wish
- Click "Request"
- On the same ACM page, once the certificate is ready (which may require a page refresh), click on it's ID in the list to view more details.
- Scroll down to the "Domains" section. You will need the CNAME name and value for the next steps.
- Navigate back to your custom domain's DNS records and create a new CNAME record
- Set the "host" value in the DNS record to the "CNAME name" value on the ACM page
Note
You will probably need to remove the apex domain from the "CNAME name" string. For example the full string might be like this in ACM: "_ac99de995b3684610896a128107a237f.login.example.com", you will only need the string up until the end of the subdomain like this: "_ac99de995b3684610896a128107a237f.login"
- Set the "value" in the DNS record to the "CNAME value" on the ACM page
- Set the "TTL" to "1 Min" and save
- Keep refreshing the ACM page until you can see that the certificate is no longer "Pending validation". This might be a good time to go grab a coffee as it can take a while.
In the AWS Console, navigate to your Elastic Beanstalk Environment and then:
- Go to "Configuration"
- Scroll to "Instance traffic and scaling" and click "Edit"
- Scroll to the "Listeners" section and click "Add listener"
- For "Listener port", enter 443
- For "Listener protocol", select "HTTPS"
- For "SSL certificate", select the certificate you made earlier in the dropdown
- For "SSL policy", select "ELBSecurityPolicy-2016-08"
- Leave the "Default process" as "default"
- Click save to close the modal
- Scroll to the bottom of the page and click "Apply"
At this point you should be able to navigate to your now secure custom domain to access your application, for example "https://login.example.com".