Day 46 of 100 Days : Securing Sensitive Data and Hosting Static Websites with Amazon S3

Today, we’ll explore two critical use cases for Amazon S3: restricting access to sensitive data using bucket policies and hosting a static website. This hands-on guide will demonstrate how to implement these concepts step-by-step.


Scenario 1: Restricting Access to Sensitive Data

As a DevOps Engineer, you might need to store sensitive information in an S3 bucket and ensure that even users with broader S3 access can't access this specific bucket. Here's how to secure your bucket:

Step 1: Create an IAM User

  1. Navigate to the IAM Console.

  2. Create a user named demo-s3-bucket-user.

    • Assign console access with a custom password.
  3. Do not attach any permissions initially to demonstrate default behavior.

Step 2: Test Default Access

  1. Open an incognito window and log in with the new IAM user credentials.

  2. Navigate to S3 in the AWS Console.

  3. Notice that the user cannot list or access any S3 buckets (expected behavior).

Step 3: Grant S3 Permissions

  1. In the IAM Console, attach the AmazonS3FullAccess policy to the IAM user.

  2. Refresh the S3 Console for the IAM user.

  3. The user can now list all buckets and access files within them.

Step 4: Restrict Access with Bucket Policies

  1. Go to the S3 Console and select your bucket.

  2. Navigate to the Bucket Permissions tab and locate the Bucket Policy section.

  3. Click Edit and use the AWS Policy Generator to create a policy. Here's an example:

  4. Save the policy.

Step 5: Verify Restrictions

  1. Switch back to the IAM user.

  2. Attempt to access the bucket or download files.

  3. The user will now see an "Insufficient Permissions" error, even though they have S3 full access.


Scenario 2: Hosting a Static Website on S3

S3 provides a cost-effective way to host static websites.

Step 1: Prepare Your Website Files

  1. Create or download a simple This_is_Munilakshmi.html file. (You can use W3Schools for sample templates.)

Step 2: Upload Files to S3

  1. Create a new S3 bucket.

  2. Upload the This_is_Munilakshmi.html file to the bucket.

Step 3: Enable Static Website Hosting

  1. Go to the Properties tab of the bucket.

  2. Scroll to Static Website Hosting and enable it.

  3. Specify This_is_Munilakshmi.html as the Index Document.

  4. Save changes.

Step 4 : Set Permissions for Public Access

  1. Allow public access to the files:

    • Go to the Permissions tab of your S3 bucket.

    • Under Block public access (bucket settings), click Edit.

    • Uncheck Block all public access to allow anyone to access your website files.

    • Confirm the changes by clicking Save.

  1. Configure bucket policy to allow public access:

    • In the Permissions tab, click on Bucket Policy.

    • Paste the following JSON policy to allow public read access to all objects in the bucket:

    • Click Save changes to apply the policy.

Step 5: Access the Website

  1. Copy the Bucket Endpoint provided in the Static Website Hosting section.

  2. Open the URL in a browser to see your static website live.


Hands-On Exercise

  1. Secure Your Bucket: Use the provided JSON policy to block access to your bucket for all users except yourself. Test it with multiple IAM users.

  2. Host a Website: Create a simple static website using HTML, upload it to S3, and enable hosting.


Key Learnings

  • Bucket Policies are essential for controlling access to sensitive data.

  • Hosting static websites on S3 is a cost-effective solution for simple web applications.

Conclusion
We’ve explored how to effectively host static websites using Amazon S3. By understanding bucket policies, configuring static hosting, and testing deployment, you now have the foundational knowledge to host your own static websites on AWS. With the scalable and cost-effective features of S3, you can ensure reliable website delivery to users worldwide.

Keep experimenting, keep building, and let your curiosity guide you toward mastering AWS. Happy learning! 🚀