DEV Community

Cover image for AWS Storage Services Tutorial: Amazon S3 Basics
fvgm-spec
fvgm-spec

Posted on

AWS Storage Services Tutorial: Amazon S3 Basics

AWS Storage Services Tutorial: Amazon S3 Basics

In this tutorial, we will delve into one of the foundational AWS storage services: Amazon S3 (Simple Storage Service). Amazon S3 is a highly scalable, durable, and secure object storage service that is designed to store and retrieve vast amounts of data from anywhere on the web. This tutorial will provide you with both theoretical insights and practical hands-on exercises to get you started with Amazon S3.

Table of Contents

  1. Introduction to Amazon S3
  2. Creating an S3 Bucket
  3. Uploading and Managing Objects
  4. Pros and Cons from both approaches
  5. Access Control and Permissions
  6. Data Management Features
  7. Conclusion

1. Introduction to Amazon S3

Amazon S3 is an object storage service that provides developers and IT teams with a simple and scalable storage solution. It's designed to store and retrieve vast amounts of data, such as images, videos, backups, and logs. Each piece of data is stored as an object, consisting of the actual data, a unique key (filename), and metadata.

2. Creating an S3 Bucket

An S3 bucket is a container for storing objects. Your first S3 bucket can be created using AWS CLI or through the AWS Console (User Interface), so we will perform both approaches.

Creating bucket from console

Creating a Bucket from the Console is a very straightforward process, you just need to log in to AWS Console and search S3 in the search bar, once there click the button Create bucket

S3 bucket creation from console

The following screen will appear, these options coresponds to your Bucket name, the AWS Region where you wish to store your data, and some other configurations that generally, are chosen as default, unless you need to set customized and advanced settings before clicking Create bucket in the end of the page.

Configuring your bucket

Once these settings are done, you will have set your first bucket in the S3 storage service.

Now let's do the same but using AWS CLI!

Creating bucket from AWS CLI

This step assumes that you have configured your AWS CLI locally, if this is not the case you can follow this link in order to configure your AWS Command Line Interface.

You can run the line above in your favorite command line interface (CLI) or the one installed by default in your laptop aws s3api create-bucket --bucket your-unique-bucket-name --region your-preferred-region --create-bucket-configuration LocationConstraint=your-preferred-region, please just replace your-unique-bucket-name with a globally unique name and your-preferred-region with the AWS region of your choice after the parameters --region and --create-bucket-configuration LocationConstraint. In the case of your bucket name this link will guide you on the naming rules for buckets Bucket naming rules.

aws s3api create-bucket --bucket your-unique-bucket-name --region your-preferred-region
Enter fullscreen mode Exit fullscreen mode

You will receive the following output in your command line:

Creating bucket from CLI

3. Uploading and Managing Objects

Uploading data to your bucket is a process that can also be done from AWS Console and from CLI, so let's show how to do it in both cases

Uploading data from AWS Console

Once you created your bucket, you just need to fill it with data coming from multiple sources (local flat files, SQL connections, API requests, among others) and on different formats (text, images, etc...). You just need to get in the bucket, and click the button Upload

Uploading from console

There you can add files or folders, by clicking on one or the other button, or dragging and dropping any object in the selected area

Uploading files

Then click on the Upload button at the end of the page.

Uploading files from AWS CLI

Now, let's upload a file to your S3 bucket using the CLI.

aws s3 cp your-file.txt s3://your-unique-bucket-name/
Enter fullscreen mode Exit fullscreen mode

I just uploaded an excel file that I had stored locally by running the line above

Uploading file using CLI

File loded to bucket

I have written a tutorial previously that covers how to do the same loading data actions from CLI but using an incredible python library called awswrangler

You can read it and put it into action from my blog

3. Pros and Cons: Creating S3 Buckets using AWS CLI vs. AWS Console

When it comes to creating Amazon S3 buckets, you have the choice between using the AWS Command Line Interface (CLI) or the AWS Management Console (User Interface). Each option comes with its own set of advantages and disadvantages.

AWS CLI

Pros:

  • Automation and Scripting: The CLI allows for automation of bucket creation and management tasks through scripts, making it easy to repeat tasks and maintain consistency.
  • Efficiency: For users comfortable with command-line interfaces, the CLI can be faster and more efficient, especially for bulk operations.
  • Integration: It's easy to integrate AWS CLI commands into your custom applications or scripts for seamless integration with other processes.

Cons:

  • Learning Curve: For users unfamiliar with command-line interfaces, there might be a learning curve to understand and use CLI commands effectively.
  • Potential Errors: Mistakes in commands could lead to unintended actions, potentially affecting your resources or data if not used carefully.

AWS Console (User Interface)

Pros:

  • Visual Interface: The UI provides a visual representation of your resources, making it easier for users who prefer a graphical interface.
  • Ease of Use: Creating buckets through the UI is straightforward, requiring minimal technical expertise or familiarity with command-line tools.
  • Validation: The UI often includes validation checks and prompts, reducing the likelihood of errors during the bucket creation process.

Cons:

  • Manual Process: Creating buckets through the UI can be time-consuming, especially for repetitive tasks or when managing multiple buckets.
  • Limited Automation: While the UI can be used to perform manual tasks, it lacks the automation capabilities that the CLI provides, which might be necessary for certain use cases.
  • Limited Scripting: If you need to integrate bucket creation into your custom scripts or applications, the UI might not be as flexible as the CLI.

In summary, choosing between the AWS CLI and the AWS Console for creating S3 buckets depends on your familiarity with command-line interfaces, the level of automation you require, and your preference for a visual or scripted approach. Both options have their merits, so consider your workflow and needs before deciding which one to use.

5. Access Control and Permissions

S3 offers fine-grained access control. You can control who can access your bucket and objects. By default, all newly created buckets and objects are private.

Bucket permissions

Making an object public, can be also done from AWS Console by editing the Block public access in the Permissions page shown above, I will show how to do it from CLI

aws s3api put-object-acl --bucket your-unique-bucket-name --key your-file.txt --acl public-read
Enter fullscreen mode Exit fullscreen mode

Setting public access

6. Data Management Features

Amazon S3 provides various features for managing your data:

  • Versioning: Enable versioning on your bucket to keep multiple versions of an object.
  • Lifecycle Policies: Define rules to automatically transition objects to different storage classes or delete them after a specified period.
  • Cross-Region Replication: Replicate objects across different regions for disaster recovery.

7. Conclusion

In this tutorial, we've covered the basics of Amazon S3, from creating buckets to uploading objects and managing access. Amazon S3's scalability, durability, and rich feature set make it a fundamental service for various cloud-based applications.

To explore further, you can learn about advanced features such as S3 event notifications, data encryption, and using S3 with other AWS services.

Remember, this is just the beginning of your journey into AWS storage services. Happy exploring!

Feel free to check the official documentation for more in-depth information and advanced features.

Stay tuned for more tutorials on AWS storage services!

Top comments (0)