How to Point Your Domain to AWS CloudFront Easily
To point your domain to
CloudFront, create a CNAME or A Alias record in your DNS pointing to the CloudFront distribution domain name. Use Route 53 for easy alias setup and attach an SSL certificate in AWS Certificate Manager for HTTPS support.Syntax
To point your domain to CloudFront, you create DNS records that link your domain name to the CloudFront distribution's domain name.
- CloudFront Domain Name: The unique URL AWS gives your distribution, like
d1234abcd.cloudfront.net. - DNS Record Type: Use
A Aliasrecord in Route 53 orCNAMErecord in other DNS providers. - SSL Certificate: Attach a certificate from AWS Certificate Manager to enable HTTPS.
json
Type: A Alias (Route 53) or CNAME (other DNS) Name: your custom domain (e.g., www.example.com) Value: CloudFront distribution domain (e.g., d1234abcd.cloudfront.net) TTL: 300 seconds (recommended) Example in Route 53: { "Type": "A", "Name": "www.example.com", "AliasTarget": { "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": "d1234abcd.cloudfront.net.", "EvaluateTargetHealth": false } }
Example
This example shows how to create an alias record in AWS Route 53 to point www.example.com to a CloudFront distribution.
json
{
"Comment": "Create alias record for CloudFront",
"Changes": [
{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "www.example.com.",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"DNSName": "d1234abcd.cloudfront.net.",
"EvaluateTargetHealth": false
}
}
}
]
}Output
Route 53 creates an alias record pointing www.example.com to d1234abcd.cloudfront.net
Common Pitfalls
- Using a
CNAMErecord for the root domain (example.com) instead of an alias record, which is not supported by most DNS providers. - Not attaching an SSL certificate to CloudFront, causing HTTPS errors.
- Forgetting to update DNS TTL or waiting for DNS propagation.
- Using the wrong CloudFront domain name or missing the trailing dot in DNS records.
text
Wrong (CNAME at root domain): www.example.com CNAME d1234abcd.cloudfront.net example.com CNAME d1234abcd.cloudfront.net # This will fail Right (Alias for root domain in Route 53): example.com A Alias d1234abcd.cloudfront.net www.example.com CNAME d1234abcd.cloudfront.net
Quick Reference
- Use A Alias record in Route 53 for root domains.
- Use CNAME for subdomains if not using Route 53.
- Attach SSL certificate in AWS Certificate Manager for HTTPS.
- Wait for DNS propagation (usually minutes to hours).
Key Takeaways
Create an A Alias record in Route 53 pointing your domain to the CloudFront domain name.
Attach an SSL certificate in AWS Certificate Manager to enable HTTPS on your domain.
Use CNAME records only for subdomains if not using Route 53; root domains require alias records.
Ensure DNS records have correct values and wait for propagation before testing.
Avoid common mistakes like using CNAME at root domain or missing SSL setup.