AWS

How to Create Folder on S3 From EC2 Instance

AWS allows the user to store data on the cloud using a Simple Storage Service (S3) bucket. The user can create a folder and store data on the cloud using AWS CLI commands and these commands can access AWS resources from anywhere. AWS resources can be managed from the virtual machine created on the EC2 instance.

This post demonstrates how to create a folder on S3 from an EC2 instance.

How to Create Folder on S3 from EC2 Instance?

Before heading towards the instructions, it is required to create an EC2 instance. After that, follow these simple steps to learn how to create a folder on the S3 bucket from the EC2 instance.

Step 1: Connect to the Instance

Select the instance and click on the “Connect” button:

Copy the command from the “SSH client” section:

Paste the copied command to the terminal and change the path of the private key pair file:

Step 2: Download AWS CLI

Type the following command to download the AWS CLI file in the zipped format:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

Unzip the AWS CLI file:

unzip -u awscliv2.zip

Step 3: Install AWS CLI

Install the AWS CLI on the instance:

sudo ./aws/install

Verify that the AWS Command Line Interface (CLI) has been installed on the system:

aws --version

In our case, running the above command will display the “aws-cli/2.11.7” version:

Step 4: Configure AWS CLI

Configure the AWS CLI using IAM credentials from the AWS account:

aws configure

To learn how to configure the AWS CLI, click here:

Use the following command to get the list of S3 buckets:

aws s3 ls

Step 5: Create a Folder on the S3 bucket

Following syntax can be used for creating a folder on the S3 bucket:

aws s3api put-object --bucket [BucketName] --key [FolderName]/ --acl public-read --content-length 0

Change the [BucketName] and [FolderName] to the name of your S3 bucket and folder you want to create:

aws s3api put-object --bucket upload31 --key my-folder/ --acl public-read --content-length 0

Running the above command will create a folder on the S3 bucket:

Step 6: Verify Folder Creation

Verify the folder creation on the S3 bucket by heading into the S3 dashboard and click on the “Buckets” page from the left panel:

Click on the bucket name:

It can be observed that inside the bucket, a folder has been created successfully:

That’s all about creating a folder on the S3 bucket from the EC2 instance.

Conclusion

To create a folder on the S3 bucket from the EC2 instance, create and connect to the EC2 instance. Download and install AWS CLI to use its commands on the EC2 instance. It is required to configure AWS CLI to use AWS CLI commands. After that, create a folder on the S3 bucket from the instance using the AWS CLI command. This guide has explained how to create a folder on S3 from an EC2 instance.

About the author

Talha Mahmood

As a technical author, I am eager to learn about writing and technology. I have a degree in computer science which gives me a deep understanding of technical concepts and the ability to communicate them to a variety of audiences effectively.