How to create a folder in AWS S3 bucket?
You can create a folder in S3 bucket either from AWS management console or using AWS API.
Create a new folder in AWS S3 bucket from management console:
- Log in to the AWS management console
- Navigate to your S3 bucket and get inside the bucket.
- Click on “Create folder” to create a new folder.
- Provide a name to the folder and click “Create folder”
Create a new folder in AWS S3 bucket using AWS CLI:
1 2 3 4 |
## Create a single folder aws s3api put-object \ --bucket --key mydir/ |
Additional resource: replicate your entire local directory structure in AWS S3 bucket
You can also upload your entire directory structure in AWS S3 bucket from your local system. In this way you can create multiple folders in AWS S3 bucket at once. You also have option to choose file extension to include or exclude while uploading to S3 bucket.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
## Create a multiple files and folders mkdir -p mydir/mydir1 mydir/mydir2 mydir/mydir3 echo "hello" > mydir/mydir1/myfile.txt echo "world" > mydir/mydir2/myfile.json echo "welcome" > mydir/mydir3/myfile.yml ## Copy the files and folders to S3 bucket aws s3 cp mydir s3://cloudaffaire/ \ --recursive \ --exclude "*.json" ## List all your files and folders aws s3 ls s3://cloudaffaire/ \ --recursive ## Where cloudaffaire is the bucket name |
Note: You cannot create multiple folders (keys) inside your bucket without any files (objects) inside them.
Hope this solves your issue, keep learning and keep sharing.