Manage AWS S3  with CLI

Manage AWS S3 with CLI

Subscribe to my newsletter and never miss my upcoming articles

Pre-requisite

Create a S3 bucket

ohooo Now it's time to explore S3 CLI commands πŸ€“

Hmm Where to start 🧐

If you aware on linux commands same thing applies for s3 as well. Yes you are right

cp -> to copy file between S3 or Local machine to S3 or S3 bucket to local machine
mv -> to move file between S3 or Local machine to S3 or S3 bucket to local machine
rm -> to remove file from S3
ls   -> to list files

We call file as object in the aws terminology

πŸ’‘Tip you can represent the S3 with bucket name / with the arn accesspoints of the bucket. In general accesspoints are used to call s3 within aws network.

How to create S3 access point? πŸ€”

Within your bucket

image.png

Once created you can copy the arn of access point

image.png

access arn looks something like below

arn:aws:s3:us-east-1:<<accountnumber>>:accesspoint/<<accesspointname>>

In below example we will just look for bucket name

Command 1 cp

This is similar to copy and pasting a file from one location to other

$ aws s3 cp <<filename>> s3://<<bucket1>>/

Above will copy file from local file to s3 bucket.

You can play with multiple combinations as below. Below copies file from bucket to local machine

$ aws s3 cp  s3://<<bucket1>>/ <<filename>>

To copy file from one s3 bucket to another

$ aws s3 cp  s3://<<bucket1>>/ s3://<<bucket2>>/

Command 2 mv

This performs move action to your file. This is something like you cut and paste a file.

Command is simple use mv inplace of cp

$ aws s3 mv <> s3://<>/

Above will move file from local file to s3 bucket.

Try playling with multiple combination as how we did in copying a file

Command 3 rm

This is similar to deleting a file

$ aws s3 rm s3://<<bucketname>>/<<path>>/filename.txt

Above deletes the filename.txt file from the s3 bucket

⚠️Use --recursive flag to delete all files under a folder

$ aws s3 rm s3://<<bucketname>>/folder --recursive

Command 4 ls

To list all the buckets in your account

$ aws s3 ls

To list files within your bucket

aws s3 ls s3://<bucketname>/folder

To list subfolder and files in it use --recursive flag

aws s3 ls s3://mybucket/folder --recursive

Delete a bucket

Inorder to delete the bucket

$ aws s3 rb s3://<<bucketname>>

In next our post let's see some advanced actions in s3 using CLI

Hope you find this useful. Give πŸ‘ for more posts from us. We also run a youtube channel TechPechu in Tamil( Indian regional Language) do subscribe as moral support! πŸ˜€

Β 
Share this