AWS Custom Domain Redirect with S3 and Route 53
Tags: webdev, aws, s3, route53
Published: 2022-02-18 02:36:47

Working with a client who has been using Zoom video conferencing frequently, I suggested a pretty URL to help clients access the  Zoom meetings.

I decided that I wanted to create a URL that was something like `https://zoom.custom-domain.com/` that would redirect to Zoom meeting link such as `https://us02web.zoom.us/j/94220614975?pwd=et9bd32Av2JC2yCtQifmA8ZoRpfxB6Nr`. In the past, I would construct the redirect using `.htaccess` or through the domain name registrar console. 

The client had a static site using a custom domain that was hosted on AWS using S3, CloudFront, and Route 53. I initially thought I could do this with the hosted zone for the client's domain name. I soon learned AWS has a different process for this type of redirect. Log into your AWS console and follow along.

## S3 Bucket Redirect

To create the redirect, we need to start by creating an S3 Bucket. It didn't make much sense to me at first, but we will connect the dots later. 

1. Navigate to the S3 service in your console.
2. We used the domain URL to name our bucket _zoom.custom-domain.com_. Be sure to uncheck the **Block _all_ public access** under **Block Public Access settings for this bucket** section. You will need to check the box that appears to acknowledge this change.
3. Click the **Create bucket** button.
![Create S3 Bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vv7h6cati9e2ydvq4f2c.png)
4. Click the bucket name in the list of buckets to open the bucket.
5. Select the **Properties** tab.
6. Scroll to the bottom of the page and click the **Edit** button within the **Static website hosting** section.
7. Select the _Enable_ radio button under **Static website hosting**.
8. Select the _Redirect requests for an object_ radio button under **Hosting type**.
9. Enter the redirect URL within the **Host name** field.
10. Select your Protocol.
11. Click the **Save changes** button to complete.
![Edit Static Hosting](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xe3sspkh4bxzqrpbze7z.png)

Our redirect is now in place and you can test by scrolling back down to the **Static website hosting** section and using the redirect link.


![Verify Redirection Link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t0zhtfj4kh3dv45ubgw4.png)

## Add Redirect to Route 53

1. Navigate your browser to Route 53 service and click on the **Hosted zones** link to list the hosted zones.
2. Select/click the hosted zone we would like to add a record too.
3. Under the **Records** section click the **Create record** button.
4. Toggle the _Alias_ on.
5. Enter your subdomain value in the **record name** field. In our example it is _zoom_.
6. Under the **Route traffic to** option, select **Alias to S3 website endpoint**. Select your region and then select the S3 bucket redirect created above.
7. Click the **Create records** button.
![Create Hosting Record](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9igcv2v186m7q7cqsdh.png)

Once the host record propagates, the URL should redirect. Test it out in your browser.

## Conclusion

This wasn't the solution I expected when I started on this path, but the implementation is simple. Hopefully, you found these instructions useful. If you have any comments, feel free to share them.

Best of luck and cheers!