惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
D
Docker
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
月光博客
月光博客
小众软件
小众软件
量子位
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
罗磊的独立博客
博客园 - 叶小钗
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
C
Check Point Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
4 Practical Boto3 Scripts for S3 Every DevOps Engineer Sh...
Muhammad Zub · 2026-04-27 · via DEV Community
Cover image for 4 Practical Boto3 Scripts for S3 Every DevOps Engineer Should Know

Muhammad Zubair Bin Akbar

Working with AWS S3 through the console is fine until you need automation, repeatability, and control. That’s where Boto3 comes in. In this post, we’ll walk through four practical Python scripts to manage S3 efficiently.

1. List All S3 Buckets with Creation Dates

A simple script to get visibility into your S3 environment.

import boto3
s3 = boto3.client('s3')
response = s3.list_buckets()
print("S3 Buckets:\n")
for bucket in response['Buckets']:
    print(f"Name: {bucket['Name']} | Created On: {bucket['CreationDate']}")

Enter fullscreen mode Exit fullscreen mode

Why this matters:

Useful for audits, inventory tracking, or quick checks across accounts.

2. Upload a File to S3 with Error Handling

Uploading files is common but handling failures properly is what makes scripts production-ready.

import boto3
from botocore.exceptions import FileNotFoundError, NoCredentialsError, ClientError
s3 = boto3.client('s3')
file_name = "test.txt"
bucket_name = "your-bucket-name"
object_name = "uploads/test.txt"
try:
    s3.upload_file(file_name, bucket_name, object_name)
    print("File uploaded successfully.")
except FileNotFoundError:
    print("The file was not found.")
except NoCredentialsError:
    print("Credentials not available.")
except ClientError as e:
    print(f"AWS Error: {e}")

Enter fullscreen mode Exit fullscreen mode

Why this matters:

Prevents silent failures and gives clear debugging output.

3. Download Files from S3 with Progress Tracking

For large files, progress tracking makes a big difference.

import boto3
s3 = boto3.client('s3')
bucket_name = "your-bucket-name"
object_name = "large-file.zip"
file_name = "downloaded.zip"
def progress_callback(bytes_transferred):
    print(f"Transferred: {bytes_transferred} bytes")
s3.download_file(
    bucket_name,
    object_name,
    file_name,
    Callback=progress_callback
)
print("Download complete.")

Enter fullscreen mode Exit fullscreen mode

Why this matters:

Gives visibility into long running downloads especially useful in automation pipelines.

4. Create and Delete S3 Buckets Programmatically

Automating bucket lifecycle management is useful in testing and dynamic environments.

import boto3
from botocore.exceptions import ClientError
s3 = boto3.client('s3')
bucket_name = "my-unique-bucket-name-12345"
# Create Bucket
try:
    s3.create_bucket(
        Bucket=bucket_name,
        CreateBucketConfiguration={
            'LocationConstraint': 'eu-west-1'
        }
    )
    print("Bucket created successfully.")
except ClientError as e:
    print(f"Error creating bucket: {e}")
# Delete Bucket
try:
    s3.delete_bucket(Bucket=bucket_name)
    print("Bucket deleted successfully.")
except ClientError as e:
    print(f"Error deleting bucket: {e}")

Enter fullscreen mode Exit fullscreen mode

Note:

Make sure the bucket is empty before deleting, otherwise the delete operation will fail.

Final Thoughts

These four scripts cover the most common S3 operations:

  • Visibility (listing buckets)
  • Data movement (upload/download)
  • Resource lifecycle (create/delete)

They’re simple, but extremely useful when building automation around AWS.

As you scale, you can extend these with:

  • Logging
  • Retry mechanisms
  • Parallel uploads/downloads

This is the kind of practical automation that saves time in real environments.