Setting Up An S3 Static Website Using AWS CLI: Description

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

AWS CLI S3 Static Web site.

md 2/23/2022

Setting Up an S3 Static Website Using AWS CLI

Description
In this article, I'll be setting up an S3 bucket website. I'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.

1. Open a terminal session and log in to the provided EC2 instance via SSH using the credentials provided
on the lab page:

ssh -i <key_name.pem> ec2-user@<PUBLIC IP>

2. Create an S3 Bucket from AWS CLI

Create an S3 bucket in the us-east-1 region, replacing <UNIQUE_BUCKET_NAME> with a unique bucket
name, and using the S3 API:

aws s3api create-bucket --bucket <UNIQUE_BUCKET_NAME> --acl public-read

3. Modify the Newly Created Bucket to Be an S3 Website Bucket

1/3
AWS CLI S3 Static Web site.md 2/23/2022

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

4. Modify Provided S3 Policy File and Use It to Modify the Bucket Policy

Open the policy_s3.json file:

vim policy_s3.json

Copy the json file content in it.

{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<UNIQUE_BUCKET_NAME>/*"
}
]
}

Save and exit the file.

5. Use the S3 policy file to modify the bucket policy so your objects are publicly accessible, which is a
requirement for S3 static websites:

aws s3api put-bucket-policy --bucket <UNIQUE_BUCKET_NAME> --policy


file://policy_s3.json

6. Clone our web site from github Page and Upload File to S3 Website Bucket

sudo apt-get install git


git clone https://github.com/Eser-U/freelanceweb.git
cd designer

6. Upload the all files to your S3 website bucket:

2/3
AWS CLI S3 Static Web site.md 2/23/2022

aws s3 cp ./ s3://<UNIQUE_BUCKET_NAME> --recursive

7. Verify Your S3 Static Website Is Working

Enter the S3 website URL for your bucket in the browser to ensure it's working.
You can also test from the terminal using the curl command:

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

8. To delete all the objects from an S3 bucket, --recursive option can be used after the specified bucket
name as shown below.

aws s3 rm s3://bucket-name --recursive

9. To delete the bucket give command shown below.

aws s3 rb s3://bucket-name

10. Instead of 8th and 9th step you can force to delete, so you can imply that command shown below

aws s3 rm s3://bucket-name --recursive --force

Thank You!

3/3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy