Back to Home

How to Attach a Domain to a Static Website in S3

Connect a custom domain and CDN distribution to your static website hosted on Amazon S3.

1. Create CloudFront Distribution

In CloudShell type:

aws cloudfront create-distribution \
--origin-domain-name your-bucket-name.s3.us-east-1.amazonaws.com \
--default-root-object index.html

2. Get Distribution Domain Name

After creation, AWS assigns a domain (e.g., d123456abcdef.cloudfront.net). You will need this for the next steps.

3. Create ACM Certificate

Request a public certificate for your domain in ACM.

4. Update Route 53 Record

Create a CNAME or A (Alias) record in Route 53 pointing your domain to the CloudFront distribution.

5. Update Cloudfront with custom domain

DIST_ID="YOUR_DISTRIBUTION_ID"
DOMAIN_NAME="portfolio.yourdomain.com"
CERT_ARN="YOUR_CERT_ARN"

ETAG=$(aws cloudfront get-distribution-config --id $DIST_ID --query "ETag" --output text)
aws cloudfront get-distribution-config --id $DIST_ID --query "DistributionConfig" > config.json
jq --arg domain "$DOMAIN_NAME" --arg cert "$CERT_ARN" \
'.Aliases = {"Quantity": 1, "Items": [$domain]} | .ViewerCertificate = {"ACMCertificateArn": $cert, "SSLSupportMethod": "sni-only", "MinimumProtocolVersion": "TLSv1.2_2021"}' \
config.json > updated-config.json

aws cloudfront update-distribution \
--id $DIST_ID \
--distribution-config file://updated-config.json \
--if-match $ETAG