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 10, 2020 in Python by Pradeep
• 120 points

edited Jul 13, 2020 by MD 124 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,220 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
123 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
612 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,120 points
517 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
2,547 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

Hi @ Prajwala  All the members here, I ...READ MORE

answered Sep 14, 2020 in Python by Richa sharma
5,958 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,220 points
158 views