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)

Aug 1, 2019 in Python by Priyanka
750 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
• 3,040 points
2,014 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, 2020 in Python by Gitika
• 65,910 points
684 views
0 votes
1 answer

How to remove all of the data in a table using Django?

Hello @kartik, Inside a manager: def delete_everything(self): ...READ MORE

answered Aug 12, 2020 in Python by Niroj
• 82,880 points
3,781 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP