Create a static S3 website
Published: 2024-01-05 19:11:33

Step 1: Create a bucket
- Sign in to AWS console and open **S3** service using the link (https://console.aws.amazon.com/s3/).
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o6j0w643wnz3uqgswaj2.png)
- Select **Create bucket**. Enter the **bucket name**(Ex. Hello) and choose the **region** where you want to create bucket.Leave the other settings as default.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jb9ds5gnzzjunv4lxcgl.png)

- Then, choose **Create** option to create the bucket.


Step 2: Enable static website hosting

- Now, bucket is created. Under the bucket list select the bucket you have created.Then, To enable static web hosting go to **Properties** tab of the selected bucket.
- Look for Static website hosting, choose **Edit**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jd050rd1cxc2r7pyrh4j.png)

- Then, under Static website hosting, choose **Enable**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f9gyunglk868jc2tv1k2.png)

- In Index document, enter the index file name of the index document, 
  typically **index.html**(you have to create one for your 
  website)
- In Error document, enter the error file name of the error document, typically **error.html**(you have to create this one for returning when an error occurs)
- Click **Save changes**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gajzvh69pdtw2wrtxcbf.png)

Step 3: Edit Block Public Access settings

- Click into your bucket and then select the ** Permissions** tab at the top
- Under Public access settings click **edit**.


- Now disable **Block all public access** and click **save changes**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zs15yri11b3768fwg19w.png)
-It will ask for confirmation to unblock public access as shown below. Type confirm and click confirm .

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/284f1cepeep9zyoe3qg3.png)


Step 4: Add a bucket policy that makes your bucket content publicly available
- Under **Permissions** tab you will find Bucket policy and click **edit** to add bucket policy.

- Add the following policy and click **Save**.

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/90flxb0k1gmjjhoc9vuv.png)
Step 5: Configure an index document
- Create an index.html file.Save it locally and the filename should match the index document name that you entered in step 2.Then upload the file in the bucket you created as shown below. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fn83503j4jvm6cyk26jp.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08ijlp255q6ujj0n1rny.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vy6nahxlbqzc1k0brchf.png)



Step 6: Configure an error document
- Create an error.html file.Save it locally and the filename should match the error document name that you entered in step 2.Then upload the error.html file in the bucket you created as shown in above screen shot.

Step 7: Test your website endpoint
- To check your website Go to **Buckets** and select **Properties**.At the bottom of the page,under Static website hosting, choose your **endpoint** below to see your website as shown in above screen shot.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cvqusxomxl1ole8wh9s.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bm7m6oob4gd3vc8fz49l.png)
Step 8: Clean up
- Delete the resources if you created this website for learning purpose.