Skip to main content

A context manager for custom resources

Project description

LBR Context Manager

The best tool for AWS lambda-backed custom resources since sliced cheese!

How is it used

I'm glad you asked!

First pip install lbr-context, then in your custom resource handler:

from lbr_context import CfnContext


def handler(event=None, context=None):
    event = event or {}
    request_type = event['RequestType'].upper()
    with CfnContext(event, context) as cfn:
        if 'CREATE' in request_type:
            # handle a create here
            pass
        elif 'UPDATE' in request_type:
            # handle an update here
            pass
        elif 'DELETE' in request_type:
            # handle a delete here
            pass

So what makes this better

One of the big pains experienced when writing custom resources is getting it wrong, because this can cause your resource to be in an IN_PROGRESS state for a long time.

This context manager addresses that, and will catch any uncaught exception. When it catches an exception, it sends the FAILED request to the event's endpoint, so CloudFormation knows your custom resource failed to create/update/delete.

On top of that, this context manager sets a timer for when the lambda is about to run out of time, so that it will make sure the FAILED request is sent, even if your lambda's timeout is improperly configured.

Project details


Download files

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

Files for lbr-context, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size lbr_context-0.2.1.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page