Automate AWS Virtual Machines (EC2) Management with Python and AWS CLI Tools

In this tutorial I will show how to automatically list, create and terminate Amazon EC2 instances with simple Python Scripts.

Before we get started, the following will be required:

  1. An AWS account with admin or power user privileges.
  2. Some experience working with Python and the command line interface.
  3. Access to a Linux shell environment with an active internet connection.

Workstation Configuration

The workstation to be used must have the following installed:

  • Python3
  • Boto3
  • AWS CLI Tool

With Python3 you will already have pip installed and by default on any UNIX based system you should have Python3 installed.

Install the needed tools with the command below, it is advisable to create a virtual environment but not compulsory you can notice i’m using one in the terminal above:

pip install awscli boto3 -U --ignore-installed six