Day 82 -Deploying a Static Website on AWS S3๐Ÿš€๐ŸŒ

Day 82 -Deploying a Static Website on AWS S3๐Ÿš€๐ŸŒ

ยท

4 min read

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:

  1. 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. ๐Ÿ“๐Ÿ—‚๏ธ

  2. 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. ๐ŸŒ๐Ÿ–ฅ๏ธ

  3. 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. ๐Ÿ”๐ŸŒ

  4. 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 ๐Ÿชฃ

  1. Log in to your AWS Management Console. ๐Ÿ–ฅ๏ธ๐Ÿ”

  2. Navigate to the S3 service by clicking on โ€œServicesโ€ in the top-left corner and selecting โ€œS3โ€ under the โ€œStorageโ€ section. ๐Ÿ“ฆ

  3. Click on the โ€œCreate Bucketโ€ button. ๐Ÿ†•

  4. Choose a unique bucket name that reflects your website (e.g., my-static-website). โœจ

  5. Select the appropriate region for your websiteโ€™s audience (choose the region closest to your target audience for better performance). ๐ŸŒ

  6. Leave other settings as default or adjust them as needed. โš™๏ธ

  7. Click on โ€œCreate Bucketโ€ to create your S3 bucket. ๐ŸŽ‰

Step 2: Upload Website Files ๐Ÿ“

  1. Once the S3 bucket is created, click on its name to open the bucket details. ๐Ÿง

  2. Click on the โ€œUploadโ€ button to upload your website files. ๐Ÿ“ค

  3. Drag and drop or choose the files from your local system. ๐Ÿ“‚๐Ÿ–ฑ๏ธ

  4. 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 ๐ŸŒ

  1. In the bucket properties, navigate to the โ€œStatic website hostingโ€ section. ๐Ÿ› ๏ธ

  2. Select the โ€œUse this bucket to host a websiteโ€ option. ๐Ÿ–ฑ๏ธ๐ŸŒ

  3. For the โ€œIndex document,โ€ enter the filename of your default homepage (usually index.html). ๐Ÿ 

  4. For the โ€œError document,โ€ enter the filename of your custom error page (optional, usually error.html or 404.html). ๐Ÿšซ

  5. 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 ๐Ÿ”“

  1. In the bucket properties, navigate to the โ€œPermissionsโ€ tab. ๐Ÿ›ก๏ธ

  2. Under Block public access (bucket settings), choose Edit. ๐Ÿ–Š๏ธ

  3. Clear Block all public access, and choose Save changes. โœ”๏ธ

  4. Under Bucket Policy, choose Edit. ๐Ÿ“

  5. 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/*"
            ]
        }
    ]
}
  1. Replace Bucket-Name with the name of your bucket. ๐Ÿชฃโœ๏ธ

  2. Click on โ€œSaveโ€ to apply the bucket policy, allowing public read access to objects in the bucket. โœ…

Step 5: Test and Verify ๐Ÿ”

  1. Test your website by accessing the S3 bucket endpoint (e.g., my-static-website.s3.amazonaws.com) in a web browser. ๐ŸŒ๐Ÿ–ฅ๏ธ

  2. 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! ๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘ฉโ€๐Ÿ’ป

Did you find this article valuable?

Support Nilkanth Mistry by becoming a sponsor. Any amount is appreciated!

ย