Hackforge Academy

Category: python

Upload Files from Python to AWS S3

Published on 15 Sep 2026

Explanation

An S3 bucket stores objects such as images, documents, backups, and datasets.

Code:

import boto3
s3 = boto3.client('s3')
s3.create_bucket(Bucket='my-python-bucket')

Explanation

Boto3 can upload a local file to an S3 bucket.

Code:

s3.upload_file('report.pdf', 'my-python-bucket', 'reports/report.pdf')

Explanation

Text content can be stored directly in S3 using put_object.

Code:

s3.put_object(Bucket='my-python-bucket', Key='message.txt', Body='Hello from Python')

Explanation

The download_file method copies an S3 object to the local filesystem.

Code:

s3.download_file('my-python-bucket', 'reports/report.pdf', 'report-copy.pdf')

Explanation

Python can list objects stored inside an S3 bucket.

Code:

response = s3.list_objects_v2(Bucket='my-python-bucket')
for item in response.get('Contents', []):
    print(item['Key'])

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community