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
• 2,870 points
576 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

+5 votes
2 answers

EC2 instance status check failed

Creating a snapshot from an EBS volume ...READ MORE

answered Mar 27, 2018 in AWS by DragonLord999
• 8,380 points
333 views
0 votes
1 answer

Adding Keypair to existing EC2 instance

No you can't. The reason is KeyPair ...READ MORE

answered Apr 8, 2018 in AWS by code_ninja
• 6,120 points
31 views
+2 votes
2 answers

Is it possible to ping AWS EC2 instance

Start by adding a new EC2 security group inbound ...READ MORE

answered Apr 9, 2018 in AWS by hemant
• 5,750 points
311 views
0 votes
3 answers
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
• 56,160 points
145 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
• 56,160 points
272 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,550 points
196 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
• 56,160 points
321 views