Setting Up an S3 Static Website Using AWS CLI

30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we’ll be setting up an S3 bucket website. We’ll also verify the website is accessible and working as expected. S3 bucket websites are excellent for hosting single-page, customer-facing content, as they are easy to set up and offer the same high availability and scalability as S3.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create an S3 Bucket from AWS CLI
  1. Create an S3 bucket in the us-east-1 region, giving your bucket a globally unique name, using the S3 API:

    aws s3api create-bucket --bucket <UNIQUE_BUCKET_NAME> --acl public-read
Modify the Newly Created Bucket to Be an S3 Website Bucket
  1. Issue the AWS S3 API CLI command to enable the "Static website hosting" property of your bucket. In this same command, you’ll also provide the index.html page, which is what your bucket URL will serve:

    aws s3 website s3://<UNIQUE_BUCKET_NAME> --index-document index.html
Modify Provided S3 Policy File and Use It to Modify Bucket Policy
  1. Open policy_s3.json using vi/vim.
  2. Put in the name of your bucket.
  3. Save and exit the file.
  4. Use the S3 policy file to modify the bucket policy so your objects are publicly accessible, which is a requirement for S3 static websites:

    cd
    aws s3api put-bucket-policy --bucket <UNIQUE_BUCKET_NAME> --policy file://policy_s3.json
Create a Basic `index.html` Page and Upload File
  1. Create a basic HTML page:

    echo "<html><center><h1>My Static Website on S3</h1></center></html>" > index.html
  2. Upload the index.html file to your S3 website bucket using the AWS S3 API CLI:

    aws s3 cp index.html s3://<UNIQUE_BUCKET_NAME>
Verify Your S3 Static Website Is Working
  1. Enter the S3 website URL for your bucket in the browser to ensure it’s working.
  2. You can also test from the terminal using the curl command:

    curl http://<UNIQUE_BUCKET_NAME>.s3-website.us-east-1.amazonaws.com

Additional Resources

You are a DevOps Engineer for an up-and-coming e-commerce company, Pinehead Inc. Your company is about to launch its annual sale. In anticipation of the traffic spike when the sale goes live, management has asked you to come up with a solution for the burst of traffic, which involves a static landing page that will be highly available and scalable as well as easy to maintain in the shortest amount of time. From this landing page your website visitors will then be able to click and move on to other parts of the website.

When confirming and checking resources created through AWS CLI on the AWS console, ensure you're in region us-east-1 (N. Virginia).

To begin, open a terminal session and log in to the provided EC2 instance via SSH using the credentials provided on the lab page:

ssh cloud_user@<PUBLIC IP>
What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?