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, 2019 in Python by Suraj
578 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, 2019 by Priyaj
• 57,530 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, 2019 in Python by Omkar
• 69,060 points
10,805 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, 2019 in Python by Noel Deepak Palle
1,751 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, 2019 in Python by Greg
5,475 views
0 votes
1 answer

TypeError: 'Element' object is not subscriptable

Hey Bharti, You can get some idea from ...READ MORE

answered Feb 18 in Python by Gitika
• 29,090 points
911 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, 2019 in Python by Omkar
• 69,060 points
92 views
0 votes
0 answers

I am trying to click the button but it is not working and it is drop list ..

<a class="quickreports btn btn3d tbbtn" href="javascript:" style="position:static" ...READ MORE

Dec 1, 2019 in Python by anonymous
• 120 points
127 views
0 votes
0 answers

print(lst[-2:-4]) is not possible why?

Mar 13 in Python by Anubhuti
• 120 points
225 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
1,577 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
• 57,530 points
116 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
• 57,530 points
52 views