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
81 views
Do you have a default VPC?

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+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,120 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
• 65,840 points
593 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
• 65,840 points
10 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
415 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
11,771 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
82 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
980 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
21 views
0 votes
1 answer

'python' is not recognized as an internal or external command

I have met same issue when I ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 56,120 points
60 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,120 points
47 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,120 points
15 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.