AWS Automation with Python (Boto3) Basics — Part 1

Saurabh Shah
2 min readMar 19, 2020

--

Boto3 is the Amazon Web Services (AWS) SDK for Python which provides an easy to use, object-oriented API, as well as low-level access to AWS services. All that Boto3 does is call AWS APIs. It’s an fantastic way to Enhance your Python Skills which can be used to develop AWS Automation Scripts or lambda Functions or even use AWS Cloud Development Kit ( CDK ).

Let’s put our first Step where i will practically Show you how we can use Boto3 real quick

Jupyter Notebook
#I have Python 3.7.4 Installedfrom platform import python_version
print(python_version())
#list s3 Bucket Names in My Environmentimport boto3
s3 = boto3.client('s3')
Buckets = s3.list_buckets()
for each in Buckets['Buckets']:
print(each['Name'])

With 4 line of small Code we are ready with s3 Bucket Names. Here we have used ‘Client’ Interface to call AWS Service which provides a low-level interface to AWS whose methods map close to 1:1 with service APIs. There is one more Way to call AWS Service , let’s have a look.

Jupyter Notebook
#list s3 Bucket Names in My AWS Environmentimport boto3
s3 = boto3.resource('s3')
Buckets = s3.buckets.all()
for each in Buckets:
print(each.name)

Here we have used ‘Resource’ Interface to call AWS Service which provides an higher-level abstraction than the raw, low-level calls made by service clients.

Summary

Today we learnt how Boto3 offers two distinct ways of accessing AWS abstracted APIs:

  1. Client: low-level service access
  2. Resource: higher-level object-oriented service access

Next Articles of boto3 will Focus on :

  • Difference between “Client” and “Resource” Interface . Which Interface to use when ?
  • What are different ways to connect to AWS using boto3 ? How to Connect to AWS Service using different Sessions and Profiles ?
  • Starting with AWS Scripts and lambda Functions
  • Coming soon…check the space for AWS Devops Blogs.

Thank-you for Spending your time and Reading this blog. Please Share if you feel it’s worth. Happy Learning!

--

--

Saurabh Shah

DevOps Engineer Sr. working primarily with DevOps, CI/CD, Amazon Web Services, Automation, VMware & Networking.