Skip to content

Nithya-95/Static_Website_Hosting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Static_Website_Hosting

Hosting a static website using AWS S3.


Objective

Create a static café website that showcases the café visually through images and provides business details, such as:

  • Location of the store
  • Business hours
  • Café’s telephone number

Tasks Involved

All resources will be created using the AWS CLI:

  1. Create an S3 bucket.
  2. Create a new IAM user with full access to Amazon S3.
  3. Upload files to Amazon S3 to host the static website.
  4. Create a script to update the website automatically when local files change.

Architecture Diagram

Architecture Diagram


Steps

1. Launch an EC2 Instance

  • Use a Linux image to create a CLI machine.

2. Configure AWS CLI

  • Install and configure AWS CLI on the EC2 instance.

3. Create an S3 Bucket

  • Bucket name must be unique (e.g., combination of initials and random numbers).
  • Example command:
aws s3api create-bucket --bucket <your-unique-bucket-name> --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2
  • Example successful output:
{
    "Location": "http://<your-unique-bucket-name>.s3.amazonaws.com/"
}

4. Create a New IAM User with Full S3 Access

  • Create the user:
aws iam create-user --user-name nithya
  • Create login profile:
aws iam create-login-profile --user-name nithya --password Test123!

5. Attach S3 Policy to the User

  • List AWS-managed policies containing "S3":
aws iam list-policies --query "Policies[?contains(PolicyName,'S3')]"
  • Attach full access policy to the user:
aws iam attach-user-policy --policy-arn arn:aws:iam::aws:policy/<policy-name> --user-name nithya

6. Adjust Bucket Permissions

  1. Go to the S3 console → your bucket → Permissions.
  2. Under Block public access, choose Edit, deselect Block all public access, and save.
  3. Under Object Ownership, choose Edit, select ACLs enabled, acknowledge, and save.

7. Upload Files to S3 Using CLI

  • Enable website hosting:
aws s3 website s3://<your-bucket>/ --index-document index.html
  • Upload files recursively:
aws s3 cp /home/ec2-user/sysops-activity-files/static-website/ s3://<your-bucket>/ --recursive --acl public-read
  • Verify files:
aws s3 ls <your-bucket>

8. Verify Website

  • Go to PropertiesStatic website hosting → confirm it is enabled.
  • Open the Bucket website endpoint URL to view the live website.

9. Automate Updates with a Script

  • Create a batch script:
vi update-website.sh
  • Add the following content:
#!/bin/bash
aws s3 sync /home/ec2-user/sysops-activity-files/static-website/ s3://<your-bucket>/ --acl public-read
  • Make it executable:
chmod +x update-website.sh
  • Test the script:
./update-website.sh
  • Optional: set a cron job to run this script automatically for continuous sync.

10. Testing

  • Edit index.html locally:
vi sysops-activity-files/static-website/index.html
  • Example edits in VI:

    • Change bgcolor="aquamarine"bgcolor="gainsboro"
    • Change bgcolor="orange"bgcolor="cornsilk"
  • Save changes (Esc:wq) and run the update script:

./update-website.sh
  • Verify changes on the live website.

Congratulations! Your static website is now hosted on AWS S3 and can be updated automatically using the batch script.

About

Hosting a Static website using AWS S3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors