Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use root device attach time instead of launch time to get EC2 instance age #129

Closed
atqhg23 opened this issue Oct 31, 2022 · 5 comments · Fixed by #131 or #132
Closed

Use root device attach time instead of launch time to get EC2 instance age #129

atqhg23 opened this issue Oct 31, 2022 · 5 comments · Fixed by #131 or #132

Comments

@atqhg23
Copy link
Contributor

atqhg23 commented Oct 31, 2022

Describe the bug
Currently, the launch time is used to determine the age of the EC2 instance, but this value is reset when someone restarts the instance allowing users to indefinitely keep an instance from being cleaned up.

To Reproduce

  1. Launch an EC2 instance
  2. Make note of the launch time
  3. Stop and start the instance
  4. The launch time is updated to when the instance was started

Expected behavior
I looked into this and it seems like looking at the root volume attach time is the best way to determine the actual age of an instance.

@mlevit
Copy link
Owner

mlevit commented Nov 3, 2022

Thanks for raising this @atqhg23. Really interesting discovery. Let me look into it and see what the best approach would be.

@atqhg23
Copy link
Contributor Author

atqhg23 commented Nov 30, 2022

The issue with using the root volume attach time is that the root volume can be replaced which would return the wrong time if it had been replaced.

I checked with AWS on this, and it seems like the best approach would be to use the attach time of the instance's primary ENI since the primary ENI cannot de detached or deleted until the EC2 instance is deleted as well. The primary ENI can be identified by looking at the DeviceIndex, the primary ENI will always have the DeviceIndex set to 0.

@mlevit
Copy link
Owner

mlevit commented Nov 30, 2022

Thanks for that info @atqhg23. I've made the change within https://github.com/servian/aws-auto-cleanup/tree/better-ec2-launch-time

Mind testing it out for me? 😄

@atqhg23
Copy link
Contributor Author

atqhg23 commented Dec 1, 2022

Will do, thanks!

@atqhg23
Copy link
Contributor Author

atqhg23 commented Dec 2, 2022

This worked! Thanks again for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants