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
121 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,160 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,120 points
995 views
0 votes
0 answers

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

for i in cnames:     print(i)     df_csv[i] = (df_csv[i] - ...READ MORE

Jul 14 in Python by anonymous
12 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,120 points
17 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
552 views
+2 votes
11 answers

How to print array/ list without brackets in python?

name=["a","b","c"] print (', '.join(name)) It will simply take all ...READ MORE

answered Apr 18, 2018 in Python by aayushi
• 750 points
16,482 views
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
99 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,232 views
0 votes
1 answer

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

950down voteaccepted It's because any iterable can be ...READ MORE

answered May 15, 2018 in Python by ariaholic
• 7,320 points
29 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,160 points
56 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,160 points
19 views