Hosting a Static Website on Amazon S3 Using AWS CLI
Bytes & Brews | Featured scripts have been tested for Linux & Windows
Welcome back to our weekly Bytes & Brews and I would like to begin by wishing you a Happy New Year 2024! May this year be a canvas of opportunities where dreams take flight, aspirations find their wings and each day unfolds like a precious gift waiting to be unwrapped.
Introduction
In the digital age, hosting a website is easier than ever, especially with cloud services like Amazon Web Services (AWS) offering simple and cost-effective solutions. Amazon S3 (Simple Storage Service) provides an excellent platform for hosting static websites, like the one shown below.
With AWS Command Line Interface (CLI), the process becomes even more streamlined. This week’s guide will walk you through hosting a static website on Amazon S3 using the AWS CLI, enabling you to deploy your website swiftly and efficiently.
Step 1: Install and Configure AWS CLI
Ensure you have the AWS CLI installed on your local machine. If not, download and install it from the official AWS CLI website. After installation, configure the AWS CLI by running the following command and providing your Access Key ID, Secret Access Key, region, and default output format:
Step 2: Create an S3 Bucket for Your Website
Using the AWS CLI, create an S3 bucket to store your website content. Choose a globally unique bucket name (replace <your-bucket-name>
with your preferred name):
Step 3: Enable Website Hosting on Your Bucket
Once the bucket is created, enable static website hosting by configuring it as a website. Replace <index-document>
and <error-document>
with your preferred index and error documents (e.g., index.html, error.html):
Step 4: Upload Your Website Content to the S3 Bucket
Upload your website files (HTML, CSS, JavaScript, etc.) to the S3 bucket using the sync command. Replace <local-folder-path>
with the path to your website files:
Step 5: Set Bucket Policy for Public Access
Configure the bucket policy to allow public access to your website content. Create a file named policy.json
with the following content:
Replace <your-bucket-name>
with your bucket name and then apply the policy to your bucket:
Conclusion
In today’s guide, we’ve created an S3 bucket, enabled website hosting, uploaded new website content, and set permissions for public access. With Amazon S3’s scalability and reliability, our website is now ready to serve visitors seamlessly.
With AWS S3’s reliability and AWS CLI efficiency, managing your website becomes hassle-free, allowing you to focus more on your content and less on infrastructure. We are now ready to explore further AWS features in the coming weeks to optimize our website for a superior online presence.
Let me know in the comments below once you give it a try on your development environment!
Happy Clouding!