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.

Source Distribution

lbr_context-0.2.1.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file lbr_context-0.2.1.tar.gz.

File metadata

  • Download URL: lbr_context-0.2.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for lbr_context-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f7a7b75241f83279d88b531178480370983dde9baee59cb04b03a60f49499624
MD5 f3e2be8a741aca66a8a835e5ed3e6fcd
BLAKE2b-256 a2fb862839e9341e219bba60b8cca01eabc56f6ca4ed4ec1721f7c5b37ac5724

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