How to check the state of a user given instance id using filters

+2 votes

I have this code but it says " str has no object instances"

def get_instant_state():
        pr_st=[each.state['Name'] for each in ec2_con_re.instances.filter(Filters=[{'Name':'instance-id',"Values":[in_id]}])]
        return render_template("trial3.html",msg=pr_st)

Jul 31 in Python by Priyanka
38 views

1 answer to this question.

+1 vote

Seems like the "ec2_con_re.instances" you are using is a string but it should be an ec2 object. First, create the ec2 object and then run the loop. Refer to the below code:

ec2_con_re = boto3.resource('ec2')
def get_instant_state(): 
        pr_st=[each.state['Name'] for each in ec2_con_re.instances.filter(Filters=[{'Name':'instance-id',"Values":[in_id]}])] 
        return render_template("trial3.html",msg=pr_st)
answered Aug 1 by Aishwarya

Related Questions In Python

0 votes
1 answer

How to access the elements of a dictionary using index ?

Suppose you have a dictionary num = ...READ MORE

answered Jul 4 in Python by Arvind
• 2,960 points
20 views
+1 vote
1 answer
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by ariaholic
• 7,340 points
114 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29 in Python by rajesh
• 1,210 points
111 views
0 votes
1 answer
0 votes
1 answer