Deploy static website to AWS

The cloud is perfect for hosting static websites that only include HTML, CSS, and JavaScript files that require no server-side processing.

In this article, you will deploy a static website to AWS.

First, you will create a S3 bucket and upload the website files to your bucket.

Next, you will configure the bucket for website hosting and secure it using IAM policies.

Next, you will speed up content delivery using AWS’ content distribution network service, CloudFront. Lastly, you will access your website in a browser using the unique CloudFront endpoint.

Prerequisites:

Topics Covered:

  • S3 bucket creation
  • S3 bucket configuration
  • Website distribution via CloudFront
  • Access website via web browser

Dependencies

Cloud Services

  • Amazon Web Services S3 - Resource hosting and deployments
  • AWS CloudFront - CDN for SPA
  • AWS EKS - Backend API
  • AWS DynamoDB - Persistent Datastore
  • AWS Cognito - User Authentication

Performance Tracking and DevOps Tools:

  • AWS CloudWatch - Performance and Health checks
  • Sentry

    • Alternates:
    • TBD
  • Google Analytics - Usage Reporting

    • Alternates:
    • Mixpanel
    • Travis (CI/CD)

Frameworks:

  • Ionic (Javascript) (Frontend)
  • Node.js (Javascript) (Backend)

Create S3 Bucket

  1. Navigate to the “AWS Management Console” page, type “S3” in the “Find Services” box and then select “S3”.

pic1

  1. The Amazon S3 dashboard displays. Click “Create bucket”.

pic2

  1. Enter a “Bucket name” and click “Next”. Note: Bucket names must be globally unique.

pic3

  1. Click “Next” again to skip over “Step 2: Configure Options”.
  2. On “Step 3: Set Permissions”, uncheck “Block all public access”.

pic4

  1. Click “Next” and click “Create bucket”.
  2. Once the bucket is created, click on the name of the bucket to open the bucket to the contents.

pic5

Upload files to S3 Bucket

  1. Once the bucket is open to its contents, click the “Upload” button.

pic6

  1. Click the “Add Files” button and drag and drop files and folders from your local computer to the S3 bucket and select “Upload”. Note: Upload the downloaded my-travel-blog starter code files.

pic7

pic8

Secure Bucket via IAM

  1. Click on the “Permissions” tab.

pic9

  1. Click on “Bucket Policy” and enter the bucket policy below replacing “my-travel-blog20” with the name of your bucket and click “Save”.
{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Sid":"AddPerm",
      "Effect":"Allow",
      "Principal": "*",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::my-travel-blog20/*"]
    }
  ]
}

pic10

You will see warnings about making your bucket public, but this step is required for static website hosting.

pic11

Configure S3 Bucket

  1. Click on the “Properties” tab and then click on “Static website hosting”.

pic12

  1. Click on “Use this bucket to host a website”.

pic13

  1. For both “Index document” and “Error document”, enter “index.html” and click “Save”.

Distribute Website via CloudFront

  1. Select “Services” from the top left corner and enter “cloud front” in the “Find a service by name or feature” text box and select “CloudFront”.

pic14

  1. From the CloudFront dashboard, click “Create Distribution”

pic15

  1. For “Select a delivery method for your content”, click “Get Started”.

pic16

  1. Under “Origin Settings”:

    • Under “Origin Domain Name”, select the S3 bucket that you just created.
    • Under “Origin Path”, enter “/” to indicate the root level.

pic18

  1. Leave the defaults for the rest of the options, scroll down, and click “Create Distribution”.

Note: It may take up to 10 minutes for the CloudFront Distribution to be created.

  1. Once the status of your distribution changes from “In Progress” to “Deployed”, copy the endpoint URL for your CloudFront distribution found in the “Domain Name” column.

pic20

In this example, the Domain Name value is d2jrxsg5m3zhq.cloudfront.net, but yours will be different.

  1. Open a web browser like Google Chrome and paste the copied endpoint URL and append “/index.html” on the end, as shown below.

pic21

No comments?

There are intentionally no comments on this site. Enjoy! If you found any errors in this article, please feel free to edit on GitHub.