简体   繁体   中英

Is there a way to list stopped EC2 instances using Boto3?

I have already tried using describe_instance_status method like in below. But it does not return any of the stopped EC2 instances. Apparently, it does not identify any stopped instances at all. Is it possible to use describe_instance_status method to list down all the stopped EC2 instances? Thanks! :)

response_one = ec2.describe_instance_status(Filters=[
    {
        'Name': 'instance-state-name',
        'Values': [
            'stopped',
            'running'
        ]
    },
],

)

print(response_one)

Use describe_instances instead

response_one = ec2.describe_instances(Filters=[
    {
        'Name': 'instance-state-name',
        'Values': [
            'stopped',
            'running'
        ]
    },
])

print(response_one)

and if you have a large number of instances, use the paginator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM