DEV Community

Cover image for How to Host a Static Website with Custom Domain, SSL, and S3 on AWS
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

How to Host a Static Website with Custom Domain, SSL, and S3 on AWS

Set up an S3 bucket

  • Go to your AWS console and search for S3. Click it.
  • Click Create Bucket. Choose a globally unique bucket name and AWS region. It must be your domain name.
  • Untick Block all public access and confirm it, since we want our static website accessible from the internet.
  • Click Create

S3 Create Bucket

Bucket Configuration

  • Click Properties

Bucket Properties

  • Click Edit

Edit Properties

  • Click Enable at Static website hosting
  • Write index.html at Index document and error.html at Error document - optional

Static Website Hosting

  • Click Upload

Upload Files

  • Click Add files, choose index.html and error.html then Click Upload

Add Files

  • Click Permissions and Edit at Bucket policy

Bucket Permissions

  • Click Policy Generator

Policy Generator

  • Choose S3 Bucket Policy
  • Write * at Principal
  • Choose Get Object at Actions
  • Add Your S3 ARN at Amazon Resource Name (ARN)
  • Click Add Statement

Policy Statement

  • Click Generate Policy

Generate Policy

  • Copy policy

Policy JSON

  • Paste in S3 policy, add /* at the end of ARN and Click Save changes

Save Policy

  • Click Properties

Properties Tab

  • Copy this S3 URL and open in new tab

Website URL

Website Preview

Set up Route 53

  • Create hosted zone in Route 53:
  • In your AWS Console search for Route 53 under Services.

Route 53 Service

  • Under DNS management, click Create hosted zone

Create Hosted Zone

  • Inside the Domain name field input your domain name.
  • 'Type' will be Public hosted zone.
  • Click Create hosted zone.
  • Now we need to link our domain with the records in Route 53.

Hosted Zone Created

Set up CloudFront Distribution and SSL Certificate from ACM

  • In your AWS Console search for Cloudfront under Services.

CloudFront Service

  • Click Create distribution

Create Distribution

  • Choose Your S3 at Origin domain and Click Use website endpoint

Origin Domain

  • Choose Redirect HTTP to HTTPS

Redirect HTTP to HTTPS

  • Click Do not enable security protections

Security Protections

  • Click Request certificate at Custom SSL certificate - optional

Request Certificate

  • Click Next

Certificate Request

  • Write your domain name and then click Request It can take up to 30 minutes for the certificate to be issued so try to be patient.

Domain Validation

  • Choose your certificate and click Create distribution

Select Certificate

  • Click Edit

Edit Distribution

  • Click Add Item at Alternate domain name (CNAME) - optional

Alternate Domain

  • Write Your Domain Name at here and then Click Save changes

Save Domain

  • Click Error Pages and Create custom error response

Error Pages

  • Configure Error response for 403: Forbidden and 404: Not Found

403 Error

404 Error

Error Responses

Set up Route 53 Record

  • Click Services and type in Route 53, click this.
  • Click the name of your hosted zone.
  • Click Create record. Type your domain at Record name
  • Choose A - Routes traffic --- at Record type
  • Click Alias
  • Click the dropdown menu at Route traffic to and choose Alias to CloudFront distribution.
  • Choose the distribution you provisioned previously or paste your distribution.

Note: the only available region is US East (N. Virginia)[us-east-1]. This is due to the fact that we provisioned an SSL Certificate via AWS Certificate manager. This service is only available in US East 1.

  • Click Create Records.

Route 53 Record

Test the website

Verify that the website and the redirect work correctly. In your browser, enter your URLs.

Final Website

And that's it. Congratulations! You have completed this tutorial. Don't forget to delete your resources.


Repository: AWS Learning Labs

Top comments (0)