Skip to main content

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


Download files

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

Source Distribution

lambda_sigterm-0.1.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

lambda_sigterm-0.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file lambda_sigterm-0.1.2.tar.gz.

File metadata

  • Download URL: lambda_sigterm-0.1.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for lambda_sigterm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1484ff4b86ec4286bde7a95f1c267517d87f91f121d6e162b82c5d70dac4ad8e
MD5 c1207b3fc593a1d5c44656376a177edd
BLAKE2b-256 a41d33f4eb3fc51008693c9ae0a61abc7e215183dcbb10178fe6289e8890e6d7

See more details on using hashes here.

File details

Details for the file lambda_sigterm-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lambda_sigterm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for lambda_sigterm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f4d2c43524feb4b619cc5ef8a4cb74ef1073db107cbc088cec31e4609f8dfdc2
MD5 95395ad57d75e5ba4cdffc96553f4dd8
BLAKE2b-256 af5367bedd7a95e32de85e2f87301e057ce4b05d145111eb68202f3a87fad877

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