How to create an AWS EC2 Instance in the VPC with Boto3 module?

0 votes

Hi Guys,

I have created one VPC in AWS with the Boto3 module. Now I want to launch one EC2 instance within the VPC. How can I do that?

Oct 10 in AWS by akhtar
• 33,470 points
70 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use a network interface in your EC2 instance. It will allow you to use a subnet in a VPC as shown below. 

# Create a linux instance in the subnet
instances = ec2.create_instances(
 ImageId='ami-0de53d8956e8dcf80',
 InstanceType='t2.micro',
 MaxCount=1,
 MinCount=1,
 NetworkInterfaces=[{
 'SubnetId': subnet.id,
 'DeviceIndex': 0,
 'AssociatePublicIpAddress': True,
 'Groups': [securitygroup.group_id]
 }],
 KeyName='ec2-keypair')
answered Oct 10 by MD
• 79,390 points

Related Questions In AWS

0 votes
1 answer

How to Pass the VPC ID while creating the Ec2 instance in AWS using Python Boto3

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances( ...READ MORE

answered Jan 29, 2019 in AWS by Priyaj
• 57,700 points
1,125 views
+1 vote
2 answers
0 votes
2 answers

How to create an EC2 Snapshot in AWS Console?

To create a snapshot of your EC2 ...READ MORE

answered Feb 11, 2019 in AWS by Priyaj
• 57,700 points
204 views
0 votes
1 answer
0 votes
1 answer

How to create a VPC in AWS using Boto3?

Hi@akhtar, Amazon Web Services enables you to create ...READ MORE

answered Oct 9 in AWS by MD
• 79,390 points
55 views
0 votes
1 answer

How to create a security group in AWS with Boto3?

Hi@akhtar, You can create a new security group ...READ MORE

answered Oct 10 in AWS by MD
• 79,390 points
116 views