Skip to content

This project provides a step-by-step guide to configure and deploy a static website using AWS CLI, including bucket creation, file uploads, static website hosting, public access settings, and bucket policy attachment. It enables users to easily set up and verify the functionality of their website.

Notifications You must be signed in to change notification settings

harshartz/AWS-S3-using-AWS-CLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AWS S3 Static Website Deployment using CLI

First open your command-line interface (CLI) and proceed with configuring your details using the following command:

aws configure

1ss

Step 1: Create a Bucket

Use the following command to create a bucket:

aws s3 mb s3://BUCKET-NAME

Replace (BUCKET-NAME) with a globally unique name for your bucket. Make sure it is unique across all existing buckets. To check if the bucket is created, use the command:

2ss

Following command will list all the available buckets, and you should see your newly created bucket

aws s3 ls

3ss

Step 2: Upload Website Files

To upload files to your bucket, use the command:

aws s3 sync PATH_OF_LOCAL_DIRECTORY s3://BUCKET-NAME

Replace (PATH OF LOCAL DIRECTORY) with the path of your local directory containing the website files, and (BUCKET-NAME) with the name of your bucket. To check the uploaded files, use the command:

4ss

5ss

Following command will list all the files in your bucket.

aws s3 ls s3://BUCKET-NAME

6ss

Step 3: Static Website Hosting

To enable static website hosting for your bucket, use the command:

aws s3 website s3://BUCKET-NAME/ --index-document INDEX-DOCUMENT-NAME --error-document error.html

Replace (BUCKET-NAME) with your bucket name and (INDEX-DOCUMENT-NAME) with the name of your index document. This command configures the bucket to serve the specified index document and error page.

7ss

Step 4: Enable Public Access

To make the bucket publicly accessible, use the command:

aws s3api put-public-access-block --bucket BUCKET-NAME --public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"

Replace (BUCKET-NAME) with your bucket name. This command disables the restrictions on public access to the bucket.

8ss

Step 5: Attach Bucket Policy

Create a file using a text editor, such as Notepad, and write your bucket policy in JSON format. Here's an example policy: Replace (BUCKET-NAME) with your bucket name in the policy. Save the file.

9ss

Save the file with a .json extension.

10ss

Use the following command to upload and attach the policy to your bucket:

aws s3api put-bucket-policy --bucket BUCKET-NAME --policy file://FILE-PATH

Replace (BUCKET-NAME) with your bucket name and (FILE-PATH) with the path to the policy file you created.

11ss

That's it! Your website is now up and running.

The endpoint format for a static website hosted in an S3 bucket is:

http://BUCKET-NAME.s3-website-AWS-REGION.amazonaws.com

Replace (BUCKET-NAME) with your bucket name and (AWS REGION) with your default region (the one you set during configuration). Opening this endpoint will allow you to check if the website is running correctly.

12ss

13ss

About

This project provides a step-by-step guide to configure and deploy a static website using AWS CLI, including bucket creation, file uploads, static website hosting, public access settings, and bucket policy attachment. It enables users to easily set up and verify the functionality of their website.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published