Step 1 - Route 53 DNS
Depending on where your domain name DNS is managed, you may need to start here, or on the DNS manager of your other website hosting service.
Either way, even if you don’t manage DNS on AWS, you can still use AWS to redirect the domain.
To begin, make sure that you have access to the Authoritative name server for your domain.
Step 2 - AWS Certificate Manager
In order for you to use https successfully, you’ll have to issue & deploy an SSL certificate.
When you request the new certificate, be sure to add all the matching URL’s you may want to use, like www’s and other subdomains.
You can validate the certificate request through email or DNS validation. DNS is easiest & fastest, especially if AWS manages the DNS for your domain.
Once you submit the request, be sure to open the pending certificate and force the validation to create the correct DNS entries to help speed up the validation process. It will create 2 new records in the DNS entry.
If you manage DNS elsewhere, you’ll have to manually create these two records to verify you control the domain.
Step 3 - Create S3 Bucket
The S3 Bucket does all the work for the redirection, but in order for SSL to work, you need to first create the certificate.
Creating the bucket is easy, so long as no other AWS account has a bucket with the same name. Cross your fingers on this one!
You can accept all the default values when you’re creating the bucket, but you’ll have to later edit the a few settings to create the redirection.
Once the bucket is created, open the bucket and head over to the Properties tab. Scroll to the bottom to find the Static website hosting settings. Enable static hosting and select the ‘Redirect requests for an object’ Hosting type.
Be sure to leave off the prefix as well as any trailing slashes.
Once you’ve saved your changes, scroll to the bottom of the page and make note of the Bucket website endpoint – you’ll need it when you setup the CloudFront distribution in the next step.
You can test your redirect setup by clicking on the long AWS URL foudn at the bottom of the Properties tab. If it gets you to the target website, you’re on the right track!
Step 4 - Create CloudFront Distribution
A few important parts to this step:
- First, remember that value you recorded in the previous step? You’ll need to input this in the first line of the setup, in the ‘Origin domain’ area. Be sure to remove the https:// from the front and the / from the end.
- For ‘Viewer protocol policy’, select the second option to Redirect HTTP to HTTPS.
- Add the Alternate domain name(s) (CNAME) you want to use to access the redirect. These values will be similar or the same as what you supplied when you requested the SSL certificate.
- Finally, you’ll have to specify the SSL certificate. This is the one you just created, and if you created it correctly, it will appear in the list at the bottom.
It will take a few minutes for the new distribution to deploy.
Step 5 - Back to Route53 (or your other DNS provider)
For this step, I’ll provide instructions on how to complete the setup on AWS in Route53. Since I don’t know what DNS you use, I can’t provide specifics, but the basic ideas are the same.
If you completed the previous steps correctly, you’ll be able to breeze through this next part. If it’s not so easy, you’ll need to go back and double-check the previous entries to make sure you entered your CNAME’s and endpoints correctly.
- The record type is A
- Route traffic to ‘Alias’, and the alias is the CloudFront distribution you created in the previous step. Again, if the list of CloudFront distributions is empty, something was not completed correctly during the previous step.
If everything went to plan, you can now try the old domain name in a browser and see if it lands you at the right spot.
Here’s a quick review of what we did:
- Make sure that your domain name is controlled by AWS. This makes it easy to point the domain to the CloudFront distribution through the Alias setup, and it also makes it easy to verify the domain for the new SSL certificate.
- Create the SSL certificate, but be sure to add the CNAME’s you want the cert to match.
- Create the S3 bucket and setup the redirect.
- Create the CloudFront distribution and input the endpoint you created on the S3 bucket. Also be sure to link up the right SSL certificate & CNAME values.
- Update your DNS and point the A record to the CloudFront distribution. Create a CNAME for the ‘www’ subdomain.