Skip to content

AWS S3 basics

1. What is AWS S3?

Amazon Simple Storage Service (S3) is an object storage service offering scalability, data availability, security, and performance.

  • Core Features:
    • Store any amount of data.
    • Highly durable (11 9’s durability).
    • Pay-as-you-go pricing.
    • Integrations with other AWS services.

2. Key Concepts

  • Buckets: Containers for storing objects.
    • Unique name within a region.
    • Permissions and versioning settings.
  • Objects: Fundamental storage entities in S3.
    • Consist of a key (name), value (data), and metadata.
  • Regions: Physical locations for buckets.
  • Storage Classes: Manage costs based on access patterns.
    • Standard, Intelligent-Tiering, Glacier, etc.
  • Lifecycle Management: Automatically transition objects between storage classes or delete them.
  • Versioning: Maintain multiple versions of objects.

Objects

Files in AWS S3 are stored as objects inside a bucket, each object has a unique key within a bucket, each object that it’s own metadata like size, creation date.

AWS S3 quickstart

Common operations

Create a Bucket

let’s create a bucket to store images, for bucket name it is unique globally(Across all AWS not only in your account), for eg if we have bucket name catalog so we need to call it catalog-[unique-suffix] for example something like catalog-PlsTnCRr245454GWX

Terminal window
aws s3 mb s3://<bucket-name> --region <region>

Replace <bucket-name> with your chosen bucket name, and name <region> with your AWS region.

Upload an Object

let assume we need to upload and image with path ./images/car-image.png. each uploaded file with be uniquely identified by key.

Terminal window
aws s3 cp ./images/car-image.png s3://<bucket-name>

Again Replace <bucket-name> with your chosen bucket name.

Download an Object

Now let’s download the uploaded image from the bucket and store it in downloads folder.

Terminal window
aws s3 cp s3://<bucket-name>/car-image.png ./downloads
List Buckets

To list all available buckets we can use:

Terminal window
aws s3 ls
List Objects in a Bucket

To list all objects within a bucket we use:

Terminal window
aws s3 ls s3://<bucket-name>

You should see the uploaded image in the listed objects.

Delete an Object

Let’s delete the uploaded image, we need for that the object key(image name) and bucket name:

Terminal window
aws s3 rm s3://<bucket-name>/car-image.png
Delete a Bucket

Now let’s clean our work and remove the bucket we created. Note that we added the --force flag to force delete non-empty buckets, but please do not use this in production.

Terminal window
aws s3 rb s3://<bucket-name> --force

Conclusion

AWS S3 is one of the most important and widely used services, in this tutorial we have discoverd essential concepts and operations like creating buckets, uploading files, and deleting files. With this foundational knowledge, we are now equipped the basic knowledge to integrate S3 into our projects.