Back to Blog
Lesson 12 of the AWS: AWS Core Services for Developers course
Cloud NativeJuly 12, 20263 min read

Introduction to Amazon S3: Object Storage for Developers

Learn the fundamentals of Amazon S3, from creating buckets to managing permissions. Master object storage for your static application assets today.

AWSS3Cloud StorageCLIDevOpsInfrastructure

Previously in this course, we initialized our backend infrastructure using Project Setup: Initializing the Web App Backend with AWS CDK. Now that our compute layer is ready, we need a place to store our application’s assets—like images, CSS, and client-side JavaScript. This lesson introduces Amazon S3, the industry-standard service for object storage.

Understanding S3 and Object Storage

Amazon S3 (Simple Storage Service) is not a file system in the traditional sense; it is Object Storage. Unlike a block storage volume attached to a server, an object consists of the data itself, metadata, and a unique identifier.

In S3, you store data in Buckets—flat containers that act as the top-level namespace. Because S3 is a globally accessible service, every bucket name must be globally unique across all AWS accounts.

Creating Your First S3 Bucket

Before we can store files, we need a bucket. While we will eventually manage this via Introduction to Infrastructure as Code with AWS CloudFormation, it is important to understand the CLI commands first.

Ensure you have your credentials configured as shown in Configuring the AWS CLI. Run the following command to create a bucket:

Bash
# Replace 'my-unique-bucket-name-2023' with a globally unique name
aws s3 mb s3://my-unique-bucket-name-2023

The mb command stands for "make bucket." If the command succeeds, you will see a confirmation message indicating the bucket was created.

Managing Bucket Permissions

By default, all S3 buckets are private. AWS enforces a "Block Public Access" setting on all new buckets. This is a critical security feature that prevents accidental data exposure.

To verify your current settings, use:

Bash
aws s3api get-public-access-block --bucket my-unique-bucket-name-2023

If you ever need to inspect the contents of your bucket, use the ls command:

Bash
aws s3 ls s3://my-unique-bucket-name-2023

Uploading Files via the CLI

To add files to your bucket, use the cp (copy) or sync commands. Let’s upload a local file to your new bucket:

Bash
# Create a dummy file
echo "Hello, S3!" > index.html

# Upload it to the bucket
aws s3 cp index.html s3://my-unique-bucket-name-2023/

The cp command uploads the file. If you wanted to upload an entire folder of static assets (like a frontend build directory), you would use aws s3 sync ./dist s3://my-unique-bucket-name-2023/.

Hands-on Exercise

  1. Create a new bucket with a globally unique name (e.g., my-app-assets-[your-name]).
  2. Create a simple test.txt file on your machine.
  3. Upload the file to your bucket using the CLI.
  4. Verify the upload by listing the bucket contents.
  5. Delete the file from the bucket using aws s3 rm s3://[bucket-name]/test.txt to keep your environment clean.

Common Pitfalls

  • Global Uniqueness: If you get an "Access Denied" or "BucketAlreadyExists" error, it’s likely because the name is taken. Try adding a random string or date to the bucket name.
  • Region Confusion: S3 buckets are global resources, but the data resides in a specific region. While you don't always need to specify a region for the command to work, it is good practice to be aware of where your data lives for latency and compliance reasons.
  • Public Access: Do not disable "Block Public Access" unless you have a specific requirement (like hosting a public website). We will cover how to safely host static content in a later lesson.

FAQ

Q: Is S3 a database? A: No. S3 is for storing files (objects). While it has high durability, it is not optimized for transactional queries like DynamoDB Data Modeling for Developers.

Q: Can I put folders in S3? A: S3 is a flat structure. While the console shows "folders," these are actually just prefixes in the object key (e.g., images/logo.png).

Recap

We have successfully created an S3 bucket, verified its private status, and uploaded a file using the AWS CLI. This bucket will eventually host the frontend of our serverless application.

Up next: We will dive deeper into Managing S3 Bucket Policies to control exactly who can read and write to your storage containers.

Similar Posts