-
Notifications
You must be signed in to change notification settings - Fork 0
3. Deploy static website in AWS S3 Bucket
To deploy your website into AWS S3, first clone this repository into your local machine by following this steps
Make sure you've git installed, to check this open any command line and type
git version
, it should return git version 2.xx.x , if not then follow these steps on this link to install git.
- Create a new folder in your computer at preferred location. Or Let's create
serverless
folder on Desktop - Open serverless folder, Go to address bar and type
cmd
(for windows operating system) to open Command Promt - For other operating system, open your choice of CLI (terminal) and go to serverless folder
- Enter following command in terminal to clone git repo
- Login into your AWS Management Console.
- Go to
Services
, and openS3
under storage section. - Click on
Create Bucket
enterwww.serverlessdemo.com
as bucketname
Bucket name should be universally unique, So if you'll get
Bucket with the same name already exists
error, then simply try a different name, also we're going to deploy a website so make sure that it should be in domain name format (start withwww.
and end with.com
.io
.net
etc.)
- Click on drop down menu under Region and select
Canada (Central) ca-central-1
- Keep rest of the setting as default and Scroll down to the end and click on
Create Bucket
- Drag and drop all folders and files from
serverless
folder towww.serverlessdemo.com
S3 bucket except.git
- Click on
Upload
at the end of the page - Go to your bucket again , then swith to
Properties
Tab - Scroll down to end of the page and check
Static Website Hosting
. It isDisabled
by default. click onEdit
besideStatic Website Hosting
Static website hosting
Enable
Hosting type asHost a static website
Index document asindex.html
Error document asindex.html
Click onSave Changes
- Go to your bucket again , then swith to
Permission
Tab - Click on
Edit
underBlock public access (bucket settings)
- Uncheck
Block all public access
and click onSave Changes
- Read the alert and type
confirm
and click onconfirm
to apply the changes
We do not want anyone to change our source code or to delete any files, So we will just give
Read Permission
to the public by assigning custombucket policy
- Enter the following policy into
Bucket Policy
by clikingEdit
beside theBucket Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "<Bucket ARN>/*"
}
]
}
Replace
<Bucket ARN>
with your bucket ARN. You'll find Bucket ARN just above thePolicy
.
- Click on Save Changes to apply these changes
- Go to your
bucket properties
, Scroll down to theStatic Website Hosting
, and click onBucket website endpoint