Reading Time: < 1 minute
This tutorial will guide you on How to create EC2 instance using boto3. We consider you already have an AWS account however if you do not have please follow the below tutorial to create an AWS account. Once you have an AWS account, You may proceed to create EC2 using Python. You should also create/grant AWS CLI access. Unlock the power of AWS by mastering the creation of EC2 instances using Boto3 in Python. This guide assumes you have an AWS account and provides step-by-step instructions for a seamless experience.
Table of Contents
Prerequisites
- You can Create EC2 Instance using Python
- You need to have an AWS account
- You need to have CLI Access
- You can create AWS account if you do not have one yet
- Install AWS CLI
- Configure credential
How to create EC2 instance using boto3
Python Code
import boto3
ec2 = boto3.resource('ec2')
Ubuntu = 'Ubuntu'
instances = ec2.create_instances(
ImageId="ami-0283a57753b18025b",
MinCount=1,
MaxCount=1,
InstanceType="t2.micro",
KeyName="tf-kp-name",
TagSpecifications=[
{
'ResourceType': 'instance',
'Tags': [
{
'Key': 'Name',
'Value': Ubuntu
}
]}])
Code Explanation
You need to import the boto3 module
initialize ec2 resource
Create a variable Ubuntu
Finally, create an instance
You can follow the tutorial “How to describe AWS EC2 instance using python boto3“
You can read more about EC2 on the official website