You are currently viewing Various types of S3 commands in AWS CloudShell

Various types of S3 commands in AWS CloudShell

Loading

In this blog you will learn about Various types of S3 commands in AWS CloudShell. You can use various S3 commands to manage your storage efficiently. Here’s a comprehensive list to help you perform common tasks like listing, creating, uploading, downloading, deleting, copying, moving and syncing files from the AWS S3 bucket.

S3 commands in AWS CloudShell

List Buckets

First of all, you have to click on CloudShell which is present at the bottom.

The CloudShell interface will look this, now you have click on the maximize button which is in the right of Actions.

Now you have write the s3 command to list all the buckets.

aws s3 ls

Now if you list the content present inside the bucket you have to use the command given below

aws s3 ls s3://firstbucket0072

Create a Bucket

If you want to create the bucket then you have to use this command. In the below commands you are creating a bucket in a particular region which is eu-north-1.

aws s3api create-bucket --bucket my-new-bucket-007 --region eu-north-1 --create-bucket-configuration LocationConstraint=eu-north-1

If you want to enables the versioning in this bucket you can use this commands.

aws s3api put-bucket-versioning --bucket my-new-bucket-007 --versioning-configuration Status=Enabled

Delete a Bucket

First of all, you have to use rm commands in the recursive manner to delete all the files present in the bucket. Then you have to use rb commands to delete the commands.

aws s3 rm s3://firstbucket0072 --recursive
aws s3 rb s3://firstbucket0072

Delete a versioned bucket

aws s3api delete-objects --bucket data3456 \
  --delete "$(aws s3api list-object-versions --bucket data3456 --output=json --query='{Objects: Versions[].{Key:Key,VersionId:VersionId}}')"

Here data3456 is the bucket name

Upload a File to a Bucket

Firs of all you have to click on action and click on the upload file. After that upload any file in my case it is JPG file.

Then you will use cp commands to copy the file into an S3 bucket,

aws s3 cp ~/DATA\ SPOOF\ \(3\).jpg s3://my-new-bucket-007/

Download a File from a Bucket

In order to download a file you have to use cp commands

aws s3 cp s3://my-bucket-name/my-file.txt .

Sync a Local Directory with a Bucket

You have to use sync commands to sync a local directory into a bucket.

aws s3 sync my-local-directory/ s3://my-bucket-name/

Sync a Bucket with a Local Directory

You have to use sync commands to sync a bucket into a local directory.

aws s3 sync s3://my-bucket-name/ my-local-directory/

Copy a File within S3

You have to use cp commands in order to copy a file within S3 bucket. But make sure you have create source bucket and destination bucket folder.

aws s3 cp s3://source-bucket/source-file.txt s3://destination-bucket/destination-file.txt

Move a File within S3

You have to use mv commands in order to move a file within S3 bucket. But make sure you have create source bucket and destination bucket folder.

aws s3 mv s3://source-bucket/source-file.txt s3://destination-bucket/destination-file.txt

Conclusion

In this blog you will learn about various types of S3 command using cloudshell such as listing all the files in the bucket, creating a bucket, uploading a file in the bucket, downloading a file in the bucket, creating with bucket with versioning enabled, deleting the files, bucket and the versioned bucket, copy the files in bucket, moving the files in bucket, syncing to the local directory to S3 bucket and syncing s3 to the local directory.

You can tell your friends or coworkers about this blog if you like it. There are social media sites like LinkedIn, Twitter, and Instagram where you can find me.