AWS CLI Usage

Table of contents

Operation on S3 Bucket:

  1. Create a S3 bucket:

     aws s3 mb s3://abhay10371 --region us-east-1
    
  2. List bucket content:

     aws s3 ls s3://abhay10371
    
  3. Upload a file from local system to AWS S3 bucket:

     aws s3 cp file.txt s3://abhay10371
    
  4. Download a file from AWS S3 bucket to local system:

     aws s3 cp s3://abhay10371/file.txt .
    
  5. Remove a file from AWS S3 bucket:

     aws s3 rm s3://abhay10371/file.txt
    
  6. Remove an empty S3 bucket:

     aws s3 rb s3://abhay10371
    
  7. Remove a non-empty S3 bucket:

     aws s3 rb s3://abhay10371 --force
    
  8. Remove a non-empty S3 bucket with versioning enabled:

     sudo dnf install python-pip3
     pip3 install boto3
     vim del_bucket.py
     =============================================================
     #!/usr/bin/env python
     import boto3
    
     s3 = boto3.resource('s3')
     bucket = s3.Bucket('bucket_name')
     bucket.object_versions.all().delete()
     =============================================================
     python del_bucket.py    # Remove the bucket contenets including delete marker.
     aws s3 rb s3://bucket_name # Finally remove the bucket.
    
0
Subscribe to my newsletter

Read articles from Abhay Kumar Pinku directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhay Kumar Pinku
Abhay Kumar Pinku

I am Abhay Kumar Pinku. I did my graduation in Electronics and Communication Engineering stream from DSEC, Anna University. I am deeply engaged in DevOps practices for seamless software development and deployment.