How to use AWS CLI to Add a Folder in Amazon S3 Bucket In AWS
Step 1: Install and Configure AWS CLI
- Install AWS CLI on your command line using the below command.
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
- Verify successful installation by checking the version of aws using below command.
aws --version
- Configure your IAM user on the AWS CLI using below command
aws configure
- You’ll have to enter your AWS Access Key ID, AWS Secret Access Key and default region name.
Step 2: List the Buckets
- Execute below command to list the buckets. Or If bucker is not exist create the bucket.
aws s3 ls
Step 3: Create Sub Folder in AWS S3
- Create a folder on AWS S3
- Execute the below command to create a folder on the AWS S3 bucket.
- Provide bucket name and the new folder’s name you want to create on the S3.
aws s3api put-object --bucket <bucket_name> --key <new_folder_name>/ --content-length 0
- You’ll get the below output on executing above command.
- Check if folder is created on AWS S3 console.
- Create a subfolder on AWS S3
- Execute the below command to create a sub folder on the AWS S3 bucket.
- Provide bucket name and the new sub folder’s name you want to create on the S3 along with the path.
aws s3api put-object --bucket <bucket_name> --key <path_to_sub_folder>
- You’ll get the below output on executing above command.
Step 4: Verify the Folder
- Verify if sub folder is generated on the existing folder on AWS S3 console.
- We can also verify this using AWS CLI by executing below command.
aws s3 ls s3://<bucket_name> --recursive
In this way, you can create sub folder on AWS S3 using AWS CLI.
How to Create Subfolders in S3 Bucket using AWS CLI
The AWS Simple Storage Service (S3) is a cloud service provided by Amazon Web Services (AWS) to store your data securely. There are different approaches to storing and retrieving data from AWS S3; one of them is using the AWS CLI provided by Amazon Web Services. In this article, we will provide you with step-by-step instructions on how to use AWS CLI to create subfolders in an AWS S3 bucket.