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 11, 2020 in AWS by akhtar
• 38,260 points
2,501 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 11, 2020 by MD
• 95,460 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
• 58,020 points
3,547 views
+1 vote
2 answers

How to create an EC2 instance in AWS Console?

Here is a step by step guide ...READ MORE

answered Feb 11, 2019 in AWS by Shubendu
2,178 views
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
• 58,020 points
1,266 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, 2020 in AWS by MD
• 95,460 points
1,640 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 11, 2020 in AWS by MD
• 95,460 points
4,260 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP