Skip to main content

Wrapper decorators for building CloudFormation custom resources

Project description

cfn-resource-timeout

This project is a decorator and validation system that takes the drudgery out of writing custom resources. You still have access to the context and event as normal, but the decorator handles serializing your response and communicating results to CloudFormation.

See cfn-lambda from Andrew Templeton if you’re looking to write your custom resources in Node.js.

Usage

  1. Copy cfn_resource.py into the directory of your lambda function handler.py, which can be done by installing with pip.

  2. Use the cfn_resource.Resource event decorators to decorate your handler like in example.py

  3. Zip up the contents and upload to Lambda

Once the function is up, copy its ARN and use it as the ServiceToken for your custom resource. For more on the requests you may receive, see this document

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Resources": {
        "FakeThing": {
            "Type": "Custom::MyResource",
            "Properties": {
                "ServiceToken": "arn:aws:lambda:SOME-REGION:ACCOUNT:function:FunctionName",
                "OtherThing": "foobar",
                "AnotherThing": 2
            }
        }
    }
}

For more on how custom resources work, see the AWS docs

Code Sample

For this example, you need to have your handler in Lambda set as filename.handler where filename has the below contents.

import cfn_resource

# set `handler` as the entry point for Lambda
handler = cfn_resource.Resource()

@handler.create
def create_thing(event, context):
    # do some stuff
    return {"PhysicalResourceId": "arn:aws:fake:myID"}

@handler.update
def update_thing(event, context):
    # do some stuff
    return {"PhysicalResourceId": "arn:aws:fake:myID"}

@handler.delete
def delete_thing(event, context):
    # do some stuff
    return {"PhysicalResourceId": "arn:aws:fake:myID"}

Running Tests

Install and run tox:

tox

The tests use mock and pytest and will give you a terminal coverage report. Currently the tests cover ~90% of the (very small) codebase.

License

This code is released under the MIT software license, see LICENSE.txt for details. No warranty of any kind is included, and the copyright notice must be included in redistributions.

History

Pending Release

  • (Insert new release notes below this line)

1.0.0 (2017-03-22)

  • Forked from RyanSB to Time Out.

  • Allow rescheduling - by raising the new built-in NoResponse exception, a resource can avoid sending any messing to CloudFormation. This is to support Lambda functions that take >300 seconds to execute and thus reschedule themselves.

0.2.2 (2016-01-29)

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

cfn-resource-timeout-1.0.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

cfn_resource_timeout-1.0.0-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cfn-resource-timeout-1.0.0.tar.gz.

File metadata

File hashes

Hashes for cfn-resource-timeout-1.0.0.tar.gz
Algorithm Hash digest
SHA256 15348a935367de3ba4590897a83ce5deea368d8508f7375dd5e9440178f0d8d9
MD5 3feda04005eac6e4525fc76741decc55
BLAKE2b-256 500f1d22bfe789dab76812a5fb69afbba2df424c03a02597ec6d3d050d62fd1b

See more details on using hashes here.

File details

Details for the file cfn_resource_timeout-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for cfn_resource_timeout-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 262dca109560d0170dd612484570064fb842b166550b0a53f3b6f5ffb30fe6c1
MD5 9aeab4ef6088a8268ce3a3ce7c26c9fb
BLAKE2b-256 1aabdae80443a2688e10ae7caded732a62db831526f4fb9fe3a7559e777e65f2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page