Skip to main content

A simple way for EC2 instances to stop/terminate themselves.

Project description

https://img.shields.io/pypi/v/self-destruct.svg?style=for-the-badge

self-destruct is a simple Python library for stopping and terminating EC2 instances from within themselves, which is not officially supported by AWS. Usage is very simple:

from self_destruct import self_destruct

self_destruct()

The only customization option is the specification of a parameter terminate: bool = True which allows the user to specify whether they want to terminate the instance or merely stop it.

Note that in order for this function to be successful, the EC2 instance must have the following permissions:

"ec2:DescribeInstances"
"ec2:StopInstances"
"ec2:TerminateInstances"

Additionally, self-destruct can be run in module mode to ensure that the instance is terminated when the Python script exits, regardless of whether any errors are raised. To run as a module, use the following commandline syntax:

python -m self_destruct [-o (stop | terminate)] (-m module | pyfile) [args ...]

When using -o, any argument other than stop will result in instance termination. This choice was made to ensure that a typo in the argument name does not result in the instance failing to terminate.

WARNING

You are responsible for ensuring that your AWS instance terminates, and the author of this package is not liable for any costs associated with the failure of this package to actually terminate your instances.

In particular, this package cannot stop/terminate your instances if self_destruct() is never run—use module-mode to ensure that an uncaught Python exception does not prevent self_destruct() from being called. There is no protection from another program or the operating system killing the program before self_destruct() can be called, even in module-mode, however. It is your responsibility to ensure that this does not happen.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

self_destruct-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

self_destruct-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file self_destruct-0.1.0.tar.gz.

File metadata

  • Download URL: self_destruct-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for self_destruct-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d1d77d9d86c18d44734e040be9d5bb3fbfaf8d43578685f9fed4d5784d8c2cb3
MD5 85ed039d751b169379075f136b903e83
BLAKE2b-256 12b875212c86b369a29d6c038f70dbc9513de5419106d342ea8f31a5e62bb9a0

See more details on using hashes here.

File details

Details for the file self_destruct-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: self_destruct-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for self_destruct-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bd3e84d9cbc93941ca74339740e83fcd81f1ba671bb81e13698b0d6c60ee1e5
MD5 f1e11d7a948c9c4ffcc4faff5ff4f6fa
BLAKE2b-256 2ff58a8288b5dc432f1a927741e6961d1f096e92569e004af6fc28b717e5e037

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page