How to Use AWS S3 for File Storage: A Step-by-Step Guide

Amazon S3 (Simple Storage Service) is a highly scalable, durable, and secure object storage service. It’s perfect for hosting static assets, backups, media files, and application data. This tutorial covers the essential steps to start using S3 for file storage.

Before diving in, ensure you have an AWS account and the AWS CLI installed. I’ll walk you through creating a bucket, uploading files, setting permissions, and managing access. Let’s get started.

Article illustration

Creating an S3 Bucket

Log into the AWS Management Console and navigate to S3. Click “Create bucket.” Choose a globally unique name (e.g., my-app-files-2024). Select a region close to your users. For most use cases, keep “Block all public access” checked for security. Click “Create bucket.”

Uploading Files

Select your bucket and click “Upload.” Drag and drop files or use the “Add files” button. You can set storage class (Standard for frequent access, Glacier for archiving) and encryption. Click “Upload” to confirm. Alternatively, use the CLI: aws s3 cp filename s3://bucket-name/

Setting Permissions and Access

To make an object publicly readable (e.g., for a website), select the object, go to “Permissions,” and edit bucket policy. Example policy to allow public read:

  • Generate a bucket policy using the AWS Policy Generator.
  • Effect: Allow, Principal: *, Action: s3:GetObject
  • Apply the policy. Note: Bucket must allow public access settings.

Using IAM Roles for Secure Access

For applications, use IAM roles with least privilege. Attach a policy like AmazonS3FullAccess (or a custom one) to the role. Then assign the role to EC2 instances or Lambda functions.

Managing Versions and Lifecycle

Enable versioning to protect against accidental deletions. Go to bucket “Properties” → “Versioning” → “Enable.” Set up lifecycle rules to transition objects to cheaper storage (e.g., Standard-IA after 30 days) or delete them after a period.

In conclusion, AWS S3 makes file storage simple and scalable. Start with a bucket, upload your files, and control access via policies. Use versioning and lifecycle policies for cost efficiency. Explore the AWS console or CLI to adapt S3 to your needs.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *