Creates a noop Lambda Extension which allows Lambda to receive SIGTERM events
Project description
Lambda SIGTERM - Allows graceful shutdown of Lambdas using Python
The Lambda Extensions API allows lambdas to register extensions. Once an extension is registered, the Lambda runtime will send a SIGTERM to the function code so the extension can collect metrics, etc.
What if you want the benefits of getting SIGTERM signals without the overhead of third-party extensions which collect metrics? Use lambda-sigterm
!
This library creates a noop extension. All the extension does is register itself with the Lambda Extensions API, then blocks on a background thread. This makes it so the Lambda handler will receive SIGTERM signals. The library code uses urllib3
(included with the Lambda Python runtime) and Python stdlib libraries, so there are no external dependencies in the Lambda environment.
Installation
$ pip install lambda_sigterm
How To Use
To use, import the lambda_sigterm
module and call the register()
function:
import signal
import lambda_sigterm
lambda_sigterm.register()
def handle_sigterm(signum, frame):
print("sigterm captured")
signal.signal(signal.SIGTERM, handle_sigterm)
Full Example
import signal
import lambda_sigterm
lambda_sigterm.register()
def handle_sigterm(signum, frame):
print("sigterm captured")
signal.signal(signal.SIGTERM, handle_sigterm)
def lambda_handler(event, context):
print("your application code has started")
register
Arguments
keyword_arg | default | description | example |
---|---|---|---|
logger |
None |
a logging Logger to use, creates a new logger if none (falsy) is supplied |
logging.getLogger('myapp') |
log_level |
logging.ERROR |
log-level for the logger if none is supplied | logging.INFO |
log_level_debug_msg |
logging.DEBUG |
log-level for debug logs | |
log_level_info_msg |
logging.INFO |
log-level for info logs | |
log_level_error_msg |
logging.ERROR |
log-level for error logs | |
lambda_runtime_api_host |
"" |
this is the extensions API host to register the extension with, if unset (default) then this is read from the environment variable AWS_LAMBDA_RUNTIME_API |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lambda_sigterm-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4d2c43524feb4b619cc5ef8a4cb74ef1073db107cbc088cec31e4609f8dfdc2 |
|
MD5 | 95395ad57d75e5ba4cdffc96553f4dd8 |
|
BLAKE2b-256 | af5367bedd7a95e32de85e2f87301e057ce4b05d145111eb68202f3a87fad877 |