Amazon S3 Simple Storage Service is a service that lets you store files in the cloud. You can also use S3 to host static websites, which are websites that don’t require server-side processing like HTML, CSS, and JavaScript files. In this guide, we’ll show you how to set up an S3 bucket for static website hosting in very simple steps.
What You’ll Need
- An active AWS account.
- Basic knowledge of S3 and the AWS Management Console.
- An existing S3 bucket.
Step 1. Enable Static Website Hosting.
- After creating the bucket, click on the bucket name to open it. In the bucket dashboard.
- Go to Bucket Properties.
Enable Static Website Hosting
- Scroll down to the Static website hosting section.
- Click Edit and then select Enable.
- In the Index document field, enter index.html. This is the main page of your website.
- Optionally, you can also set an Error document (like error.html), which will show up if a page isn’t found.
- Click Save Changes when done.
Step 2. Set Bucket Permissions.
Make the Bucket Public
By default, S3 buckets are private, meaning only you can access them. To make the website publicly accessible, you need to adjust the permissions.
Add a Bucket Policy
- Go to the Permissions tab in your bucket settings.
- Scroll to Bucket Policy and click Edit.
- Copy and paste the following policy into the policy editor.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::codemaster000/*"
}
]
}
- Replace YOUR-BUCKET-NAME with the name of your bucket.
- Click Save to apply the policy.
Step 3. Upload Your Website Files.
Upload Your Files
- In your S3 bucket, click on Upload.
- Select the files you want to upload (e.g., index.html, styles.css, images/).
- Click Upload to add the files to your S3 bucket.
Step 4. Access Your Static Website.
Find Your Website URL
- Once your files are uploaded, go back to the Properties tab of your bucket.
- Under the Static website hosting section, you will see an Endpoint URL. This is the link to your static website.
- Example URL: http://YOUR-BUCKET-NAME.s3-website-REGION.amazonaws.com
Visit Your Website
Open the endpoint URL in your browser, and you should see your static website live.
Conclusion
Setting up an S3 bucket for static website hosting is simple, and it’s a great way to host lightweight websites without worrying about servers. With just a few clicks, you can have your site live on the web. You can also explore more advanced features like custom domains and SSL certificates as you get more comfortable with AWS S3.