Build a Serverless Web Application Part 1 — S3

Yst@IT
3 min readNov 27, 2019

--

AWS Build a Serverless Web Application

This is a walk through lab based on AWS project. For more details please refer here. This walk through breaks into four parts which are

  1. Host a static website
  2. Manage users
  3. Build serverless backend
  4. Deploy a RESTful API

Host a static website

Amazon S3 hosts static web resources including HTML, CSS, JavaScript, and image files which are loaded in the user’s browser. Now, let’s get started.

AWS Build a Serverless Web Application

S3 will hold and serve all the static contents so we start by creating a bucket.

AWS Build a Serverless Web Application

Next we upload the static web files provided by aws. You can upload the files to S3 by using AWS console. You can download them from here. You can also use CLI or CloudFormation provided by AWS to complete this step. I will use CLI.

aws s3 sync s3://wildrydes-us-east-1/WebApplication/1_StaticWebHosting/website s3://YOUR_BUCKET_NAME --region YOUR_BUCKET_REGION

AWS Build a Serverless Web Application

Next, we need to config permissions to allow public access to the files. We need to

  1. Turn OFF “Block new public bucket policies” and “Block public and cross-account access if bucket has public policies”
  2. Assign “Bucket Policy”

Select bucket holds the files and click Permissions

AWS Build a Serverless Web Application

Edit “Block all public access” setting

AWS Build a Serverless Web Application

Leave the first two options ticked, click Save and confirm changes made.

AWS Build a Serverless Web Application

Finished view.

AWS Build a Serverless Web Application

Next we add “Bucket Policy” to allow public access.

AWS Build a Serverless Web Application
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::[YOUR_BUCKET_NAME]/*"
}
]
}

Finish view.

AWS Build a Serverless Web Application

Next we enable the bucket for website hosting. Go to the Properties section and click “Static website hosting”

AWS Build a Serverless Web Application

Config as the image below. Once saved, click the Endpoint to verify that everything is setup correctly!

AWS Build a Serverless Web Application

You will see the same thing if everything is setup correctly! If you see any Permission Denied messages, review the “Block all public access” and “Bucket Policy” settings.

AWS Build a Serverless Web Application

That’s it for part 1!

References

Module 1. Static Web Hosting

--

--

Yst@IT
Yst@IT

Written by Yst@IT

Cloud Solution Architect, focusing on Oracle Cloud Infrastructure currently.

No responses yet