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, 2019 in Python by Priyanka
95 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, 2019 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, 2019 in Python by Arvind
• 2,980 points
41 views
+1 vote
1 answer
0 votes
1 answer

How to a write reg expression that confirms an email id using the python reg expression module “re”?

Hey, @Roshni, Python has a regular expression module ...READ MORE

answered Jun 26 in Python by Gitika
• 33,450 points
48 views
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 aryya
• 7,370 points
226 views
0 votes
1 answer
0 votes
1 answer