Branding, UI Design / 22 July 2023 / by Qubit

AWS Static Web Application Hosting - Part 2

In this guide, we will walk through hosting a static website on AWS using five major services:

  1. AWS Route 53: For domain setup and management.
  2. AWS Certificate Manager: To secure your domain with SSL/TLS certificates.
  3. AWS S3 Bucket: For hosting static website files.
  4. AWS CloudFront: To serve the content securely and improve performance with CDN.
  5. AWS WAF: For adding a layer of security with a web application firewall.

Prerequisites

Before proceeding, ensure the following:

  • You have a domain name transferred or added to Route 53 with a hosted zone already created.
  • Basic familiarity with AWS services and the AWS Management Console.

Architecture Overview

Here’s a high-level network map of the setup:

Alt text


Step 1: Configure AWS Certificate Manager (ACM)

To use CloudFront with SSL/TLS, you must create your certificate in the US East (N. Virginia) region.

Alt text

  • Navigate to the Certificate Manager service.

Request a Certificate

Alt text

  • Click Request a Certificate.

Alt text

  • Enter your domain name. Optionally, use a wildcard if you plan to use multiple subdomains (e.g., *.yourdomain.com).

Alt text

  • Validate the certificate by creating a CNAME record in Route 53. Scroll down to the Domain Validation section, click on the certificate, and add the CNAME record as directed.

Alt text

Alt text

Alt text

  • Check Route 53 to verify the record was created successfully.

Alt text

Alt text

Alt text

Alt text

  • Once validated, the certificate status in Certificate Manager should show Issued.

Alt text


Step 2: Create an S3 Bucket for Static Website Hosting

  • Navigate to S3 and create a bucket named after your domain (e.g., yourdomain.com).

Alt text

  • Upload your static website files to the bucket.

Alt text

Alt text

  • Enable Static Website Hosting in the bucket’s properties.

Alt text

Alt text

  • Configure the bucket policy to restrict direct access and allow only CloudFront to fetch content.

Alt text

Alt text

Alt text


Step 3: Set Up CloudFront Distribution

  • Navigate to CloudFront and create a new distribution.

Alt text

Alt text

Alt text

  • Configure the origin to point to your S3 bucket.
  • Set Viewer Protocol Policy to Redirect HTTP to HTTPS for secure access.

Alt text

Alt text

  • Add a Web Application Firewall (WAF) to the CloudFront distribution for enhanced security.

Alt text

  • Add an alternative name (CNAME) in CloudFront for your domain.

Alt text

  • Test the CloudFront distribution domain to ensure it serves your website correctly.

Alt text

Alt text

  • Wait for CloudFront deployment to complete.

Alt text


Step 4: Configure Route 53

  • Navigate to your hosted zone in Route 53.
  • Create an A (Alias) record pointing to your CloudFront distribution.
  • Optionally, create a CNAME record for subdomain forwarding (e.g., www.yourdomain.com).

Alt text

Alt text

Alt text

  • The final configuration should resemble the setup below.

Alt text

Alt text


Key Findings

  • No Public Access to S3 Bucket: CloudFront fetches content securely, preventing direct access via the S3 endpoint.
  • Region-Specific Requirements: Certificates for CloudFront must be created in US East (N. Virginia).
  • CloudFront and ACM Deployment Time: Deployment can take several minutes. Be patient!
  • Policy Setup: Use CloudFront policies for added security instead of direct S3 bucket policies.

Observations & Tips

  • Avoid Multiple Hosted Zones: Use a single hosted zone to simplify management.
  • Caching Issues: If changes don’t reflect, clear your browser cache and restart.
  • Domain Redirects: Domain and subdomain redirects typically start working within 10 minutes.
  • Custom Security Policies: Use WAF for advanced security needs, such as blocking specific IPs or patterns.

This completes the second part of setting up an AWS static web application. With this setup, you now have a robust, scalable, and secure static website hosted on AWS!

Feel free to share your thoughts or ask questions in the comments below. Stay tuned for more guides!

Tags: