Boto: Python Library to Automate AWS

Sanjeev Gautam
2 min readMar 28, 2020

--

Boto is a Python package that provides programmatic connectivity to Amazon Web Services (AWS). Boto which allows you to write some handy scripts to automate simple things like starting or stopping EC2 instances or taking regular snapshots of your servers .

Installing Boto on Linux (Ubuntu)

1. You’ll first use the yum package manager to install Python and the pip Python package installer:

apt-get install python python-devel pip

2. Now we will install the Boto package via pip:

pip install boto

3. Finally, we can test if everything has been successfully installed on our Linux box:

  • python -c “import boto; print boto.Version”

Use cases

Lets start with a basic scenario: launching an EC2 instance

The above python script will connect to Amazon’s us-west region and launch an instance using AMI id: ami-6ac2a85a.

Scheduling stop instances. Let’s say you now want to stop your test environment instances at a certain time each day. Run:

You can schedule this script to run every day at a particular time by creating a cron job.

To check all IAM user using boto3 module

Here we using profile_name to define user is being use to execute the task which is configure on console using “aws configure” command.

Alternatively we can use sessions to access different accounts and regions

AWS services supported by Boto

At the moment, Boto supports more than 50 Amazon services, running the whole range from compute, database, application, and payments and billing. You can find a complete and current list on the Python.org website.

--

--