AWS S3 Storage Basics
# CHAPTER 6
AWS S3 Storage Basics
1. Introduction
If you launch an EC2 instance, you get a virtual hard drive (EBS). But what if you want to build the next Instagram? Storing millions of user-uploaded photos on an EC2 hard drive is incredibly expensive, difficult to backup, and will eventually run out of space. AWS solves massive data storage with Amazon S3 (Simple Storage Service). In this chapter, we will transition from Block Storage to Object Storage, understand S3 Buckets, configure security permissions, and host a static website directly out of storage.2. Learning Objectives
By the end of this chapter, you will be able to:- Define Object Storage and contrast it with traditional Block Storage.
- Create an S3 Bucket with globally unique naming.
- Upload and manage Objects within a bucket.
- Understand S3 Bucket Policies and Block Public Access settings.
- Host a scalable Static Website using only S3.
3. Beginner-Friendly Explanation
Imagine a traditional filing cabinet (EC2 Hard Drive / Block Storage). You have folders, sub-folders, and documents. If the cabinet gets full, you have to buy a bigger metal cabinet and physically move all the folders over. It's rigid.Now imagine a massive warehouse managed by robots (S3 / Object Storage). There are no folders. You hand a robot a box (a photo). The robot tags the box with a unique barcode (a URL), throws it onto a massive, infinitely expanding pile, and hands you the barcode. Whenever you want the photo, you just scan the barcode, and the robot retrieves it instantly. You never have to worry about the warehouse running out of space.
4. Buckets and Objects
S3 consists of two core concepts:-
Buckets: The massive root container holding your files. Bucket names must be globally unique across ALL AWS accounts in the world. (You cannot name your bucket
my-bucketbecause someone else already took it).
- Objects: The actual files (images, videos, text files) you upload into the bucket. Each object gets a unique URL.
5. Infinite Scaling and Durability
S3 is "infinitely" scalable. You do not define a size limit. You can store 1 file or 1 billion files. AWS guarantees 11 9s of Durability (99.999999999%). This means if you store 10 million files in S3, statistically, you might lose exactly one file every 10,000 years. AWS achieves this by silently copying your files to three different physical Availability Zones the second you upload them.6. S3 Security (Block Public Access)
By default, all S3 buckets are completely private and locked down to the internet. In the past, many companies accidentally uploaded sensitive customer data to S3 and made it public. To prevent this, AWS introduced the Block Public Access feature. If this switch is turned on (it is by default), S3 will violently block any attempt to make a file public, even if you write a policy telling it to do so.7. Mini Project: Host a Static Website on S3
If your website is "Static" (just HTML, CSS, and JS, with no backend PHP or Node.js processing), you do not need an EC2 instance! S3 can host static websites for pennies a month, and it can handle millions of visitors without crashing.Step-by-Step Tutorial:
- 1. Open the AWS Console and search for S3.
- 2. Click Create bucket.
-
3.
Bucket name: Enter something globally unique (e.g.,
my-aws-website-yourname-123).
- 4. Object Ownership: Leave as ACLs disabled.
- 5. Block Public Access settings: UNCHECK the box that says "Block *all* public access." Acknowledge the warning. (We are hosting a public website, so it must be public!). Click Create bucket.
- 6. Click into your new bucket. Go to the Properties tab.
- 7. Scroll to the very bottom: Static website hosting. Click Edit.
-
8.
Select Enable. For the Index document, type
index.html. Save changes.
-
9.
Go to the Permissions tab. Scroll to Bucket policy. Click Edit and paste this JSON policy (Replace
YOUR-BUCKET-NAME):
-
10.
Go to the Objects tab. Click Upload. Upload a simple
index.htmlfile from your computer.
- 11. Go back to Properties -> Static website hosting, and click the provided Bucket website endpoint URL. Your website is live to the world!
8. Best Practices
-
Use IAM for Private Access: If your EC2 web server needs to read private user photos from an S3 bucket, DO NOT make the bucket public. Attach an IAM Role to the EC2 instance granting it
s3:GetObjectpermissions. The EC2 server will magically be able to read the private bucket securely.
9. Common Mistakes
- Confusing S3 with a Database: You cannot query S3 like a SQL database. You cannot say "Find all images uploaded by user John." S3 only retrieves objects by their exact Key (Filename). Metadata indexing requires a separate database (like DynamoDB) storing the S3 URLs.
10. Exercises
- 1. Explain why S3 is an ideal storage solution for serving static images for a website compared to storing them directly on the EC2 instance's EBS volume.
11. MCQs with Answers
You are tasked with creating a new Amazon S3 bucket to store company backups. Which of the following is a strict requirement for naming the S3 bucket?
When attempting to configure an S3 Bucket Policy to allow public read access for hosting a static website, AWS rejects the policy and returns an "Access Denied" error. What is the most likely cause?
12. Interview Questions
- Q: Explain the difference between Block Storage (like AWS EBS) and Object Storage (like AWS S3). In what architectural scenarios would you use one over the other?
- Q: Explain the 11 9s of Durability guarantee in S3. How does AWS physically architect its infrastructure to provide this level of data protection against hardware failure?
13. FAQs
Q: Can I use my own domain name (e.g., www.mywebsite.com) with an S3 static website? A: Yes! You use AWS Route 53 to map your custom domain name to the S3 Bucket URL. However, to do this, your S3 Bucket name MUST exactly match your domain name (e.g., the bucket must be namedwww.mywebsite.com).