How I Use Boto3 and AWS for DevOps Automation (My Workflow) 🚀

Rohit JangraRohit Jangra
3 min read

Hey folks! 👋

As someone deep into the DevOps space, I’m constantly looking for ways to automate repetitive cloud tasks and make life easier. Recently, I’ve been working a lot with Boto3, the AWS SDK for Python, and it’s been a total game-changer for me when it comes to automating AWS resources.

In this article, I want to share how I’ve been using Boto3 in my DevOps workflows and why I think it’s a must-know tool if you’re working with AWS.


🧐 So, What is Boto3?

Boto3 is basically Python’s way of talking to AWS services like EC2, S3, IAM, Lambda, and so on.

Sure, I’ve used Terraform and Ansible before, but there are times when I need a quick Python script to spin up resources, fetch logs, or automate something very specific in AWS. That’s where Boto3 shines!


⚙️ Setting It Up

The setup is super simple.

bashCopyEditpip install boto3

You’ll also want to have your AWS CLI configured so Boto3 can pick up your credentials from there:

bashCopyEditaws configure

Once that’s done, you’re good to start scripting AWS tasks like a boss. 😎


🧩 Boto3 Structure - Resource vs Client

Something I learned early on is that Boto3 has two main ways to interact with services:

  • Resource-level: More Pythonic and easy to use

  • Client-level: Lower-level, closer to AWS API requests

Personally, I mix both depending on the task.

Example:

pythonCopyEditimport boto3

# Resource (high-level)
s3 = boto3.resource('s3')

# Client (low-level)
s3_client = boto3.client('s3')

🚀 How I Use Boto3 in My Day-to-Day DevOps Workflows

1. Launch EC2 Instances on the Fly

I often write scripts to quickly launch EC2 instances when testing automation flows or provisioning environments temporarily.

pythonCopyEditec2 = boto3.resource('ec2')

instance = ec2.create_instances(
    ImageId='ami-0abcdef1234567890',  # Use your AMI ID here
    MinCount=1,
    MaxCount=1,
    InstanceType='t2.micro',
    KeyName='my-key-pair'
)

print(f'Launched instance: {instance[0].id}')

2. Upload Logs/Reports to S3 Buckets

I automate a lot of report generation, and they always end up in S3.

pythonCopyEdits3_client.upload_file('daily-report.csv', 'my-s3-bucket', 'reports/daily-report.csv')
print("Report uploaded!")

3. Automate IAM User Creation (Useful for CI/CD pipelines)

Sometimes I need automation users for my pipelines:

pythonCopyEditiam = boto3.client('iam')

response = iam.create_user(UserName='automation-user')
print(f"Created IAM user: {response['User']['UserName']}")

4. CloudWatch Logs - Quick Monitoring Script

I’ve written Boto3 scripts to pull CloudWatch logs for quick troubleshooting:

pythonCopyEditlogs_client = boto3.client('logs')

response = logs_client.filter_log_events(
    logGroupName='/aws/lambda/my-function',
    limit=5
)

for event in response['events']:
    print(event['message'])

🛠️ Where Does Boto3 Fit in My DevOps Automation?

  • I hook Python+Boto3 scripts directly into my CI/CD pipelines (Jenkins/GitLab CI).

  • I’ve built Lambda functions using Boto3 for event-driven tasks like auto-tagging AWS resources.

  • Sometimes I use Boto3 in combination with Terraform when I need additional post-deployment automation (e.g., tagging, custom resource validation).


🧠 Lessons I’ve Learned Along the Way

  • Error handling matters! AWS API calls can fail for various reasons. Always wrap with try-except.

  • Use pagination when dealing with large datasets (especially S3 listings).

  • Stick to IAM roles with least privilege. Security is 🔑!

  • Boto3-stubs has been helpful for me during development (gives autocompletion and type hints).


💡 What’s Next?

I’m still exploring how to automate even more tasks like:

  • Scheduled cleanups of old snapshots

  • Lambda-powered auto-scaling triggers

  • Automating daily cost reports via S3 + Athena queries


✌️ Wrapping Up

If you’re a DevOps engineer like me and spend a lot of time with AWS, I highly recommend giving Boto3 a shot. It’s lightweight, flexible, and fits right into your Pythonic brain 🧠.

Would love to hear how you’re using Boto3 in your projects! Feel free to drop your tips, scripts, or feedback in the comments below. 🚀


👉 Let’s Connect!

I regularly share my DevOps learnings and automation hacks, so feel free to follow me here or connect with me on LinkedIn and GitHub!

1
Subscribe to my newsletter

Read articles from Rohit Jangra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rohit Jangra
Rohit Jangra