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,020 points
2,902 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 in AWS by MD
• 65,200 points
70 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 in AWS by MD
• 65,200 points
509 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 1 day ago in AWS by MD
• 65,200 points
14 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
• 57,680 points
1,294 views
0 votes
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
• 57,680 points
2,158 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,770 points
1,288 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 9, 2018 in AWS by Priyaj
• 57,680 points
969 views