AttributeError ec2 ServiceResource object has no attribute create instance

+1 vote

I am getting this error while trying to create an Instance on EC2 using Python boto3.

Here is the code I am using and I am getting this error:

AttributeError: 'ec2.ServiceResource' object has no attribute 'create_instance'

import boto3
ec2 = boto3.resource('ec2')
instance = ec2.create_instance(
    ImageId = 'ami-009d6802948d06e52',
    MinCount = 1,
    MaxCount = 1,
    InstanceType = 't2.micro',
    KeyName = 'nitesh',
    SubnetId = 'subnet-026hy78976jo77')
print (instance[0].id)

Thank you in Advance.

Dec 3, 2018 in AWS by Nitesh
• 3,080 points
7,330 views

1 answer to this question.

0 votes

This is an attribute error. There are no attribute as create_instance.

The attribute name is create_instances. Here is the error in your code.

import boto3
ec2 = boto3.resource('ec2')
instance = ec2.create_instances(
    ImageId = 'ami-id',
    MinCount = 1,
    MaxCount = 1,
    InstanceType = 't2.micro',
    KeyName = 'nitesh',
    SubnetId = 'subnet-id')
print (instance[0].id)
answered Dec 3, 2018 by Nabarupa

Related Questions In AWS

0 votes
1 answer

AttributeError: 'ec2.ServiceResource' object has no attribute 'send_command'

Hi@Lakshminarayanan, The send_command attribute is not available in ...READ MORE

answered Oct 7, 2020 in AWS by MD
• 95,460 points
5,273 views
0 votes
1 answer

dynamodb.ServiceResource' object has no attribute 'exceptions'.

Hi@akhtar, You'll need to use boto3.client('dynamodb') to be able to ...READ MORE

answered Jul 13, 2020 in AWS by MD
• 95,460 points
14,627 views
0 votes
1 answer

Error: 'No package Tableau server available on the EC2 Linux instance'

Hi, Tableau may not come with your ISO ...READ MORE

answered Oct 20, 2020 in AWS by MD
• 95,460 points
814 views
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,020 points
5,958 views
–1 vote
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,020 points
5,204 views
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,820 points
2,868 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How to find unused Amazon EC2 security groups?

Select all and delete there you can ...READ MORE

answered Jul 10, 2018 in AWS by Priyaj
• 58,020 points
2,248 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