ScriptAutomatizationEc2Aws is a Python script that automates the creation of an EC2 instance on AWS along with its associated Key Pair.
The goal of this project is to provide a fast, simple, and fully automated way to deploy an EC2 instance without using the AWS console.
It was originally developed during a hackathon to simplify and speed up AWS EC2 setup for quick deployments.
Before using the script, make sure you have:
- Python 3.8+
- An AWS account with the following permissions:
ec2:CreateKeyPairec2:RunInstancesec2:DescribeInstances
- AWS CLI configured or credentials stored in:
~/.aws/credentials - Python dependency: boto3
Clone the repository and install the dependencies:
git clone https://github.com/Axel-cmd/ScriptAutomatizationEc2Aws.git
cd ScriptAutomatizationEc2Aws
# (Optional but recommended) create a virtual environment
python3 -m venv venv
source venv/bin/activate # macOS / Linux
# venv\Scripts\activate # Windows
# Install dependencies
pip install boto3Before running the script, you must configure the settings in the config.json file.
Start by copying the example file:
cp config.json.example config.jsonOpen the file and fill in the required fields:
{
"region": "your-aws-region",
"instance_type": "t2.micro",
"ami_id": "your-ami-id",
"key_name": "your-keypair-name",
"private_key_path": "path/to/save/your-key.pem"
}🔍 Field Description
| Field | Description |
|---|---|
region |
AWS region where the EC2 instance will be created (e.g. eu-west-3). |
instance_type |
Type of EC2 instance to launch (e.g. t2.micro). |
ami_id |
ID of the AMI to use when launching the instance. |
key_name |
Name of the Key Pair to create or use. |
private_key_path |
Local path where the generated .pem key will be saved. |