Skip to content

Instantly share code, notes, and snippets.

@supriya-premkumar
Last active March 7, 2017 19:58
Show Gist options
  • Save supriya-premkumar/c233a34096adfdd8372b46d790b3136d to your computer and use it in GitHub Desktop.
Save supriya-premkumar/c233a34096adfdd8372b46d790b3136d to your computer and use it in GitHub Desktop.

#Access S3 from AWS CLI

##Pre-Requisite : Install AWS CLI and Configure AWS https://gist.github.com/supriya-premkumar/f51b4c61ac984c93934381dfa3d78454

1. Create S3 Bucket:

aws s3 mb s3://your-bucket-name

2. Delete S3 Bucket:

aws s3 rb s3://your-bucket-name

3. Delete S3 bucket if it has content(Object/s) in S3 bucket:

aws s3 rb s3://your-bucket-name —force

4. List S3 bucket/s:

aws s3 ls

5. Copy file from Local Machine to AWS S3:

aws s3 cp test.txt s3://your-bucket-name

6. Test if the copied file exists in the bucket:

aws s3 ls s3://your-bucket-name

7. To Sync all the folders/files from local machine to the s3 bucket:

aws s3 sync . s3://your-bucket-name/create-new-folder

8. To list all the keys in S3:

aws s3 ls s3://your-bucket-name —recursive

9. Since there is not cat command to read the file, we can use the following command to read a file

aws s3 cp s3://your-bucket-name/README -

10. To check the content size in the s3 bucket

aws s3 ls s3://your-bucket-name/folder-name --recursive | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'

11. To delete contents in the bucket

aws s3 rm s3://your-bucket-name --recursive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment