Book Image

Hands-On Enterprise Automation with Python

By : Bassem Aly
Book Image

Hands-On Enterprise Automation with Python

By: Bassem Aly

Overview of this book

Hands-On Enterprise Automation with Python starts by covering the set up of a Python environment to perform automation tasks, as well as the modules, libraries, and tools you will be using. We’ll explore examples of network automation tasks using simple Python programs and Ansible. Next, we will walk you through automating administration tasks with Python Fabric, where you will learn to perform server configuration and administration, along with system administration tasks such as user management, database management, and process management. As you progress through this book, you’ll automate several testing services with Python scripts and perform automation tasks on virtual machines and cloud infrastructure with Python. In the concluding chapters, you will cover Python-based offensive security tools and learn how to automate your security tasks. By the end of this book, you will have mastered the skills of automating several system administration tasks with Python.
Table of Contents (20 chapters)

Managing AWS instances

Now, we're ready to create our first virtual machine using boto3. As we have discussed, we need the AMI that we will instantiate an instance from. Think of an AMI as a Python class; creating an instance will create an object from it. We will use the Amazon Linux AMI, which is a special Linux operating system maintained by Amazon and used for deploying Linux machines without any extra charges. You can find a full AMI ID, per region, at https://aws.amazon.com/amazon-linux-ami/:

import boto3
ec2 = boto3.resource('ec2')
instance = ec2.create_instances(ImageId='ami-824c4ee2', MinCount=1, MaxCount=1, InstanceType='m5.xlarge',
Placement={'AvailabilityZone': 'us-west-2'},
)
print(instance[0])

In the preceding example, the following applies:

  1. We imported...