March 25, 2021 / Nirav Shah
If we want to create an EC2 instance with a single click we can go with the python automation.
We already learn why Python is used for the cloud infrastructure automation by referring below link: New Approach for the Automation: Python
Let’s get started with knowing something about boto3 and understand it properly. Boto3 is the Amazon Web Services (AWS) SDK for Python. AWS infrastructure provisioning is done with using boto3 script in python. By this Python developers create, configure, and manage AWS services.
Boto3 provides an easy to use, object-oriented API, as well as low-level access to AWS services. Boto3 is built on the Botocore, which is shared by the AWS CLI. Botocore provides the low-level clients, session and credentials and configuration data.
Core Concept of boto3
Install AWS CLI and Python Boto3
#pip install awscli #pip install boto3
Now configure ‘aws configure’ on your CLI, by entering Access key, Security key, Region name and output format- {JSON or Yaml}

You can find Access key and Security key form the My Security Credentials from the Account name.

Now we are going to create AWS infrastructure with Python automation with the help of boto3.
For that, we need to create pratice.py file and write the python automation script.
Pratice.py
When you run this script it will create VPC, InternetGateway Id, RouteTable, Subnets, SecurityGroup, KeyPair and Ec2-Instance automatically.
Run the below script and verify the output.
Python Script – Boto3-Test.py
Refer below the output of the script.

Now Refer AWS cloud console for the infrastructure output of the script.
1. VPC Created

2. RouteTable Created

3. Subnet Created

4. SecurityGroup Created

5. EC2 instance successfully created using the above parameters.

This how you can automate your infrastructure with python and minimize your manual work.
Also Read: Launch an AWS Ec2 instance for free

Nirav Shah is the Director of Eternal Web Pvt Ltd, an AWS Advanced Consulting Partner and certified Odoo Partner based in the UK. With over a decade of experience in cloud computing, digital transformation, and ERP implementation, Nirav helps enterprises adopt the right technology to solve complex business challenges. He specialises in AWS infrastructure, Odoo ERP, and web development solutions for businesses across the UK and beyond.
Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.