Welcome to Day 82 of the #90DaysOfDevOps challenge! ๐๐
Todayโs project involves hosting a static website using Amazon S3, a powerful and cost-effective object storage service provided by Amazon Web Services (AWS). Letโs dive into the details of todayโs project! ๐๐ป
Project Description ๐
Amazon S3 (Simple Storage Service) is a highly scalable and reliable object storage service offered by AWS. It allows you to store and retrieve any amount of data from anywhere on the web. In this project, we will leverage the capabilities of AWS S3 to host a static website. Unlike dynamic websites, which require server-side processing and databases, static websites consist of HTML, CSS, JavaScript, and other client-side files that can be directly served to visitors. ๐๐จ๐ฅ๏ธ
The main objectives of this project are as follows:
Upload the website files to an S3 bucket: We will create a new S3 bucket and upload the static website files to it. These files can include HTML pages, CSS stylesheets, JavaScript scripts, images, and other assets. ๐๐๏ธ
Configure the S3 bucket as a static website: S3 provides a feature to turn a bucket into a static website by enabling website hosting. Once configured, the bucket will act as a web server, serving the static content directly to visitors. ๐๐ฅ๏ธ
Set up appropriate permissions: Weโll define the necessary permissions to ensure public access to the static website. This will allow anyone with the website URL to view the content. ๐๐
Ensure cost-effectiveness and scalability: AWS S3 is known for its cost-effectiveness and scalability, making it an ideal choice for hosting static websites. ๐ฐ๐
Now that we have a clear understanding of the projectโs objectives, letโs proceed with the step-by-step resolution of the project. ๐ ๏ธ๐
Hands-on Project: Hosting a Static Website on AWS S3 ๐ฅ๏ธ
Step 1: Create an S3 Bucket ๐ชฃ
Log in to your AWS Management Console. ๐ฅ๏ธ๐
Navigate to the S3 service by clicking on โServicesโ in the top-left corner and selecting โS3โ under the โStorageโ section. ๐ฆ
Click on the โCreate Bucketโ button. ๐
Choose a unique bucket name that reflects your website (e.g.,
my-static-website
). โจSelect the appropriate region for your websiteโs audience (choose the region closest to your target audience for better performance). ๐
Leave other settings as default or adjust them as needed. โ๏ธ
Click on โCreate Bucketโ to create your S3 bucket. ๐
Step 2: Upload Website Files ๐
Once the S3 bucket is created, click on its name to open the bucket details. ๐ง
Click on the โUploadโ button to upload your website files. ๐ค
Drag and drop or choose the files from your local system. ๐๐ฑ๏ธ
Make sure to include your HTML, CSS, JavaScript, images, and any other assets required for the website. ๐๐
Step 3: Configure the S3 Bucket for Website Hosting ๐
In the bucket properties, navigate to the โStatic website hostingโ section. ๐ ๏ธ
Select the โUse this bucket to host a websiteโ option. ๐ฑ๏ธ๐
For the โIndex document,โ enter the filename of your default homepage (usually
index.html
). ๐For the โError document,โ enter the filename of your custom error page (optional, usually
error.html
or404.html
). ๐ซClick on โSave changesโ to enable website hosting for the bucket. ๐พโ
Step 4: Edit S3 Block Public Access settings and Set Bucket Policy for Public Access ๐
In the bucket properties, navigate to the โPermissionsโ tab. ๐ก๏ธ
Under Block public access (bucket settings), choose Edit. ๐๏ธ
Clear Block all public access, and choose Save changes. โ๏ธ
Under Bucket Policy, choose Edit. ๐
To grant public read access to your website, copy the following bucket policy, and paste it into the Bucket policy editor. ๐
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::Bucket-Name/*"
]
}
]
}
Replace
Bucket-Name
with the name of your bucket. ๐ชฃโ๏ธClick on โSaveโ to apply the bucket policy, allowing public read access to objects in the bucket. โ
Step 5: Test and Verify ๐
Test your website by accessing the S3 bucket endpoint (e.g.,
my-static-website.s3.amazonaws.com
) in a web browser. ๐๐ฅ๏ธYou should be able to see your static website live and accessible to the public. ๐๐ฅณ
Wrapping Up ๐
I hope you learned something from this blog. If you have, donโt forget to follow and click the clap ๐ button below to show your support. ๐ Subscribe to my blogs so that you wonโt miss any future posts. ๐๐
If you have any questions or feedback, feel free to leave a comment below. Thanks for reading and have an amazing day ahead! โ๏ธ๐
Connect with me on:
Happy Coding! ๐ป๐จโ๐ป๐ฉโ๐ป