Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.
This repository was archived by the owner on May 29, 2025. It is now read-only.

The state of ec2 instance is not matched with actual. #10

@skostrichegg

Description

@skostrichegg

Hi,

I found the state of ec2 is not matched with actual, when I entered below codes.

import boto3
rsc = boto3.resource('ec2')
a = list(rsc.instance.filter(Filters=[{'Name': 'tag:Name', 'Values': ['my_ec2_instance']}]))
a[0].state
{'Name': 'stopped', 'Code': 80}
a[0].start()
a[0].wait_until_running()
a[0].state
{'Name': 'running', 'Code': 16}
a[0].stop()
a[0].state
{'Name': 'stopping', 'Code': 64}
a[0].wait_until_stopped()
(When this blocking is released, I can check the state of EC2 is 'stopped' on AWS console page. BUT,)
a[0].state
{'Name': 'stopping', 'Code': 64}

I expected 'stopped'.

This doesn't happens every time. Sometimes it works correctly.

Could you explain me how can I fix this?
Or if something I use those API with wrong way, let me know.

My python and boto3 version is

  • Python: 3.6.8
  • boto3: 1.12.39

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions