DEV Community

Cover image for AWS S3 in 3 Minutes
Justin Wheeler
Justin Wheeler

Posted on

AWS S3 in 3 Minutes

Overview

AWS S3 stands for Simple Storage Service, which makes storage in the cloud extremely simple.

Features

The service is feature rich with everything you could possibly want from a top tier storage solution:

Terminology

These terms are widely used when discussing S3:

  • Arn: Amazon Resource Name; it's a unique id for AWS resources
  • Bucket: root object container; name must be globally unique
  • Key: object name including prefixes
  • Prefix: nested object container; name does not have to be unique
  • Object: data stored within a Bucket

Open Guide (Basics, Tips, Gotchas)

https://github.com/open-guides/og-aws#s3

Examples

Console

the console is a great place to learn, but it's bad practice to make changes in the console in a production environment. 🔥

Console 1

Console 2

https://docs.aws.amazon.com/AmazonS3/latest/user-guide/what-is-s3.html

CLI

 # lists buckets
 aws s3 ls 

 # lists objects
 aws s3 ls s3://my-bucket/     

 # upload file
 aws s3 cp file.txt s3://my-bucket/

 # download file
 aws s3 cp s3://my-bucket/file.txt .

 # removes file.txt from S3
 aws s3 rm s3://my-bucket/file.txt
Enter fullscreen mode Exit fullscreen mode

https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html

SDK (Python)

  # initialize client
  s3 = boto3.client('s3')

  # list buckets
  buckets = s3.list_buckets()
  for b in buckets:
      print(f"Bucket: {b}")

  # list objects
  bucket = s3.Bucket("my-bucket")
  for obj in bucket.objects.all():
      print(f"Object: {obj.Key}")

  # upload file
  s3.upload_file("file.txt", "my-bucket", "file.txt")

  # download file
  s3.download_file("my-bucket", "file.txt", "file.txt")

  # remove file
  s3.delete_object("my-bucket", "file.txt")
Enter fullscreen mode Exit fullscreen mode

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html

Top comments (0)