Amazon Simple Storage Service (Amazon S3) is a scalable and durable object storage service used to store files, backups, logs, media assets, and application data. A common requirement when working with S3 is organizing data using folders and subfolders. This guide explains how to create subfolders in an S3 bucket using AWS CLI in a clear and practical way.
Amazon S3 does not use a traditional file system. Instead, it stores data as objects inside buckets. Each object consists of:
In this example, logs, 2025, and january appear as subfolders even though they are part of the object key.
AWS Command Line Interface (AWS CLI) is a powerful tool that allows you to interact with AWS services using terminal commands. It is widely used for automation, scripting, and managing cloud resources efficiently.
aws --version
aws configure
This method creates a folder-like structure by uploading an empty object with a trailing slash.
aws s3api put-object --bucket my-bucket --key projects/2025/january/
You can create subfolders automatically by uploading a file to a specific path.
aws s3 cp report.pdf s3://my-bucket/reports/2025/january/report.pdf
This method is ideal for uploading directories with multiple subfolders.
aws s3 sync ./local-folder s3://my-bucket/data/
| Command | Description |
|---|---|
| aws s3 ls | List buckets or folder contents |
| aws s3 cp | Upload or download files |
| aws s3 sync | Sync local directories with S3 |
| aws s3 rm | Delete objects or folders |
No. S3 uses object key prefixes to simulate folders.
Yes. You can create an empty folder by uploading an empty object with a trailing slash.
No. S3 automatically creates the folder structure when files are uploaded.
The aws s3 sync command is best for uploading entire directory structures.
aws s3 rm s3://my-bucket/folder-name/ --recursive
Creating subfolders in an S3 bucket using AWS CLI is based on understanding object keys and prefixes. While S3 does not provide real folders, AWS CLI makes it simple to organize data using logical structures. With proper commands and best practices, you can efficiently manage files for backups, logs, and application data.
Copyrights © 2024 letsupdateskills All rights reserved