How to Point a CNAME to an Amazon S3 Bucket

As a Data Scientist or Software Engineer working with AWS, you may have already encountered Amazon’s Simple Storage Service (S3). It is a scalable, high-speed, web-based cloud storage service designed for online backup and archiving of data and applications. S3 buckets are used to store object data, including any type of data for which you require storage.

How to Point a CNAME to an Amazon S3 Bucket

As a Data Scientist or Software Engineer working with AWS, you may have already encountered Amazon’s Simple Storage Service (S3). It is a scalable, high-speed, web-based cloud storage service designed for online backup and archiving of data and applications. S3 buckets are used to store object data, including any type of data for which you require storage.

In this post, we will discuss how to point a CNAME (Canonical Name) to an Amazon S3 bucket.

CNAME is a type of DNS record that maps one domain name (an alias) to another (the canonical name). This can be especially useful when you want to mask the complex S3 URL with your own custom domain name.

Prerequisites

  1. An Amazon S3 bucket.
  2. A domain name.
  3. Access to your domain’s DNS settings.

Step 1: Create an S3 Bucket

First, you need to create an S3 bucket with the same name as your domain or subdomain. For instance, if your domain is example.com and you want to point files.example.com to S3, create a bucket named files.example.com.

aws s3api create-bucket --bucket files.example.com --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2

Step 2: Enable Static Website Hosting

Next, enable static website hosting on your S3 bucket. In the S3 console, select your bucket, navigate to the properties tab, and enable “Static Website Hosting”. Note the endpoint URL, as you’ll need it in the next step.

Step 3: Create a CNAME Record

Now, create a CNAME record in your domain’s DNS settings. The record should point your desired subdomain to the S3 bucket’s static website endpoint URL. The CNAME record might look something like this:

files.example.com. CNAME files.example.com.s3-website-us-west-2.amazonaws.com.

This record tells DNS that files.example.com is an alias for files.example.com.s3-website-us-west-2.amazonaws.com.

Step 4: Test the Setup

Finally, test the setup by accessing a file in your S3 bucket using the new domain name. If you have a file named image.jpg in your bucket, you should be able to access it at http://files.example.com/image.jpg.

Conclusion

By pointing a CNAME to an S3 bucket, you can leverage Amazon’s powerful and scalable storage solution while maintaining a clean, branded URL structure. Remember, the S3 bucket name must exactly match the domain or subdomain you’re pointing to it, and you need to enable static website hosting on the bucket.

Hopefully, this tutorial has provided you with the knowledge to successfully point a CNAME to an Amazon S3 bucket. The possibilities are vast when it comes to leveraging Amazon S3 and DNS together, so explore and experiment!

Despite the technical nature of this topic, it’s critical to understand that the alignment of your S3 bucket and your domain name can significantly impact your operations and branding. So, dive in and take advantage of this powerful combination!

Keywords: Amazon S3, CNAME, DNS record, static website hosting, bucket, domain name.


About Saturn Cloud

Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.