print(instance(0).id) TypeError: 'list' object is not callable

0 votes
import boto3
ec2 = boto3.resource('ec2')
instance = ec2.create_instance(
    ImageId = 'ami-009d6802948d06e52',
    MinCount = 1,
    MaxCount = 1,
    InstanceType = 't2.micro')
print (instance[0].id)
Jan 18 in Python by Suraj
176 views
Do you have a default VPC?

1 answer to this question.

+1 vote

Hey @Suraj, For me its working fine. You need to verify that have you verified aws credentials or not?

This is the code I used for creating an Instance.

The instance Id was displayed as an output for ec2.create_instance

Here is the instance created.

Give me some more details on your error so that I can suggest you the solution.

answered Jan 18 by Priyaj
• 56,520 points

Thank you for the reply Priyaj.

This is what I receive when I tried to print the Instance Id. As I have few more instances, I tried it as print(instance(4).id) as well. This being the 5th yet the same response. Can you help further?

Hey @Suraj you just print the instance and the index. You don't use .id.

See this:-

The instance variable here is of type list. hence you have to use

print (instance[0].id)

To get the id of the required index instance.

Hope it helps.

Hey @Suraj,

The code that you are using is correct but when you are implementing it you are changing 

print (instance[0].id) 

to 

print (instance(0).id) 

This will work fine.

The code you have mentioned in the question and the code used in the screenshot is different. In the screenshot, you have used 

print (instance(0).id)

To address the index of a list, you have to use square brackets. Try this:

print (instance[0].id)
Thank you that helped me :)
Hello @Suraj, glad you found the solution.

Related Questions In Python

0 votes
1 answer

Python TypeError: 'list' object is not callable.

The error says the list is not ...READ MORE

answered Feb 8 in Python by Omkar
• 67,480 points
1,496 views
0 votes
1 answer

i am normalizing the data set iris in python and get the error ::TypeError: 'numpy.float64' object is not callable

TRY THIS   #Nomalisation for i in names:     print(i)   ...READ MORE

answered Aug 19 in Python by Noel Deepak Palle
133 views
0 votes
1 answer

Python error "'Series' object is not callable "

Try this: df['ln_returns'] = np.log(df['Close_mid']/df['Close_mid']) df['Close_mid'](1)) doesn't seem to ...READ MORE

answered Jul 22 in Python by Greg
188 views
0 votes
1 answer

How to print a message or the error if a file is not found?

To print the message that file is not ...READ MORE

answered Jan 2 in Python by Omkar
• 67,480 points
29 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
678 views
+2 votes
11 answers
0 votes
1 answer

Raw_input method is not working in python3. How to use it?

raw_input is not supported anymore in python3. ...READ MORE

answered May 4, 2018 in Python by aayushi
• 750 points
121 views
0 votes
1 answer

What is the difference between list and tuple?

Lists are mutable(values can be changed) whereas ...READ MORE

answered May 4, 2018 in Python by aayushi
• 750 points
1,595 views
0 votes
1 answer

Python join: why is it string.join(list) instead of list.join(string)?

This is because join is a "string" ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 56,520 points
67 views
0 votes
1 answer

What are the differences between type() and is instance()?

Normally, in Python, you want your code ...READ MORE

answered Aug 6, 2018 in Python by Priyaj
• 56,520 points
25 views