Skip to content

Built a cloud automation solution using AWS S3 to help businesses efficiently manage storage—automating uploads, downloads, and bucket lifecycles for scalable applications and resilient data systems.

License

Notifications You must be signed in to change notification settings

AShirsat96/AWS-S3-operations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS S3 Operations

A Python implementation for basic AWS S3 operations using boto3. This implementation provides functions for listing, creating, uploading, downloading, and deleting S3 bucket contents.

Prerequisites

  • Python 3.8.19
  • boto3 (AWS SDK for Python)
  • AWS Account with S3 access
  • AWS Access Key and Secret Access Key

Installation

Install the required AWS SDK for Python:

pip install boto3

Configuration

You'll need to configure the following AWS credentials:

aws_accesskey = <Your Access Key>
aws_secretaccess = <Your secret access key>
myregion = <your region>
mybucket = <your bucket name>

Required Libraries

import boto3
import os
import logging

Functions

1. List Buckets

Lists all S3 buckets in your AWS account.

List_My_Buckets(aws_access, aws_secret, aws_region)

2. Create Bucket

Creates a new S3 bucket with location constraint.

create_bucket(aws_access, aws_secret, aws_region, bucket_name)

3. Upload File

Uploads a file to specified S3 bucket.

upload_file(aws_access, aws_secret, aws_region, bucket_name, file_toupload, object_name=None)
  • If object_name is not specified, the filename will be used

4. Download File

Two methods are provided for downloading files:

Method 1 (using download_fileobj):

download_file(aws_access, aws_secret, aws_region, bucket_name, file_todownload, object_name)

Method 2 (using download_file):

download_file_2(aws_access, aws_secret, aws_region, bucket_name, file_todownload, object_name)

5. List Objects

Lists all objects in a specified bucket with their sizes in KB.

list_object_v2(aws_access, aws_secret, aws_region, bucket_name)

6. Delete Object

Deletes a specific file from a bucket.

delete_object(aws_access, aws_secret, aws_region, bucket_name, file_todelete)

Error Handling

All functions include error handling using try-except blocks for ClientError exceptions and logging.

Official Documentation References

About

Built a cloud automation solution using AWS S3 to help businesses efficiently manage storage—automating uploads, downloads, and bucket lifecycles for scalable applications and resilient data systems.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages