Unable to create EC2 instance using boto3

0 votes

I am trying to create an EC2 instance using boto3 but getting an error message.

import boto3, botocore
aws_mag_con_aswapi=boto3.session.Session(profile_name="aswapi")
ec2 = boto3.client('ec2')
responce = ec2.create_instances(
    ImageId = 'ami-009d6802948d06e52',
    MinCount = 1,
    MaxCount = 1,
    InstanceType = 't2.micro',
    KeyName = 'nabarupa',
    SubnetId = '')
print (responce[0].id)
Jul 11, 2020 in Python by Pradeep
• 120 points

edited Jul 13, 2020 by MD 651 views

1 answer to this question.

0 votes

Hi@Pradeep,

I have tried the below code and it is working fine. You can use the below-given code once.

import boto3
ec2 = boto3.resource('ec2')
# create a new EC2 instance
instances = ec2.create_instances(
     ImageId='ami-00b6a8a2bd28daf19',
     MinCount=1,
     MaxCount=2,
     InstanceType='t2.micro',
)

I hope this will help.

answered Jul 13, 2020 by MD
• 95,440 points

Related Questions In Python

0 votes
1 answer

Create an ec2 instance using boto

Hi @Neel, try this script: reservations = conn.get_all_instances(instance_ids=[sys.argv[1]]) instances ...READ MORE

answered Jun 24, 2019 in Python by Varsha
603 views
0 votes
1 answer

Attach volume to existing ec2 instance using python

Yes of course that's possible with just ...READ MORE

answered Jun 24, 2019 in Python by Krina
1,332 views
+1 vote
1 answer

How to create plots using python matplotlib in IPython notebook?

I think you should try: I used %matplotlib inline in ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 58,090 points
1,182 views
0 votes
1 answer

SSH into an ec2 instance using boto

Hi @Neha, try something like thus: import boto3 import ...READ MORE

answered Jun 24, 2019 in Python by Varsha
3,447 views
0 votes
1 answer
0 votes
3 answers

i am installing wordcloud using pip but i am unable to do that ....i am getting the following error

word cloud is not supported for python ...READ MORE

answered Apr 15, 2020 in Python by anonymous
31,727 views
0 votes
1 answer

How to create new environment using conda?

Hi@akhtar, Environment means you are creating your own ...READ MORE

answered Apr 21, 2020 in Python by MD
• 95,440 points
699 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