Skip to main content

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.

Metadata

Release files for lbr-context 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lbr-context 0.2.1
File Size Uploaded
lbr_context-0.2.1.tar.gz 4.1 kB Details

Release files / lbr_context-0.2.1.tar.gz

Download URL lbr_context-0.2.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f7a7b75241f83279d88b531178480370983dde9baee59cb04b03a60f49499624
BLAKE2b-256 checksum
How to use checksums
a2fb862839e9341e219bba60b8cca01eabc56f6ca4ed4ec1721f7c5b37ac5724
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.10

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page