AWS Tutorial menu

AWS S3 Storage

Amazon S3 (Simple Storage Service) stores files of any type and size, safely and cheaply, in the cloud.

What is S3?

S3 is object storage. You do not get a disk with folders like on your laptop. Instead you get:

  • Buckets: containers for your files. Each bucket name is unique across all of AWS.
  • Objects: the files you store, such as images, PDFs, videos or backups.
  • Keys: the full name of an object, like products/shirt-blue.jpg.

S3 is used for website images, app uploads, backups, logs and data for analysis. It is designed to keep your data very safe by copying it across several data centres.

Creating a Bucket

In the console: open S3, click Create bucket, type a name and choose a region.

With the CLI (mb means "make bucket"):

Example

bash
aws s3 mb s3://ayesha-notes-2026 --region ap-south-1
Output
make_bucket: ayesha-notes-2026

Bucket name rules:

  • 3 to 63 characters
  • Only lowercase letters, numbers, dots and hyphens
  • Must be unique in the whole world, so add something personal like your name

Uploading and Downloading Files

Copy a file to the bucket:

Example

bash
aws s3 cp result-card.pdf s3://ayesha-notes-2026/2026/result-card.pdf
Output
upload: ./result-card.pdf to s3://ayesha-notes-2026/2026/result-card.pdf

List what is inside:

Example

bash
aws s3 ls s3://ayesha-notes-2026/2026/
Output
2026-10-15 11:42:03      84213 result-card.pdf

Download it again:

Example

bash
aws s3 cp s3://ayesha-notes-2026/2026/result-card.pdf ./download.pdf

To copy a whole folder and only send changed files, use sync:

Example

bash
aws s3 sync ./website s3://ayesha-notes-2026/site

The 2026/ part of the key looks like a folder in the console, but S3 is flat. It is simply part of the object's name.

Storage Classes

You can choose a storage class to save money on files you rarely open:

Storage classBest for
S3 StandardFiles used often, like website images
S3 Intelligent-TieringUnknown access patterns; AWS moves files automatically
S3 Standard-IAFiles used rarely but needed quickly
S3 Glacier classesArchives and old backups, cheapest but slower to get back

Lifecycle rules can move objects to cheaper classes automatically, for example "move logs to Glacier after 90 days".

Keeping Data Private

New buckets are private by default, and Block Public Access is turned on. Keep it that way unless you really need public files.

To share one private file for a short time, create a pre-signed URL:

Example

bash
aws s3 presign s3://ayesha-notes-2026/2026/result-card.pdf --expires-in 3600

The link works for one hour (3600 seconds), then stops working.

You can also turn on:

  • Versioning: keeps old versions when a file is overwritten or deleted
  • Encryption: S3 encrypts new objects by default

Hosting a Static Website

S3 can serve a simple website made of HTML, CSS, JavaScript and images (no PHP or database).

  1. Create a bucket and upload index.html
  2. In Properties, turn on Static website hosting and set the index document to index.html
  3. Turn off Block Public Access for this bucket and add a bucket policy that allows public reading

A bucket policy for public reading looks like this:

Example

json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::ayesha-portfolio-site/*"
  }]
}

For a real site, put CloudFront (AWS's content delivery network) in front of the bucket to get HTTPS and faster loading.

Deleting a Bucket

A bucket must be empty before you delete it. The --force option empties and deletes it in one step:

Example

bash
aws s3 rb s3://ayesha-notes-2026 --force

Exercise

Exercise

In Amazon S3, what is a bucket?

Learn AWS with a teacher

Join the CIT (Computer Information Technology) course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp