Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

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.2.0 (2017-05-03)

  • Move from urllib to requests to fix some encoding errors on Python 3

1.1.0 (2017-04-27)

  • Added Python 3 compatibility

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)

Metadata

Release files for cfn-resource-timeout 1.2.0

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

Source distribution (sdist)

Source distribution for cfn-resource-timeout 1.2.0
File Size Uploaded Provenance
cfn-resource-timeout-1.2.0.tar.gz 5.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cfn-resource-timeout 1.2.0
File Interpreter ABI Platform
cfn_resource_timeout-1.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 11.8 kB

Release files / cfn-resource-timeout-1.2.0.tar.gz

Download URL cfn-resource-timeout-1.2.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
40a28c845fa956c3d280d5de62e7a2fe1beb345aa4be40e4f27df1eaa6de38f0
BLAKE2b-256 checksum
How to use checksums
8a93b316acc91e040ccc776e2881748de71d5c0d77197a73ab50877706109617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cfn_resource_timeout-1.2.0-py2.py3-none-any.whl

Download URL cfn_resource_timeout-1.2.0-py2.py3-none-any.whl
Size 6.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
940288f76e5486432a75457d6f76885ada87ee1b8bec17c87117d8ce936bd25d
BLAKE2b-256 checksum
How to use checksums
3913e3277073a58252a9cc153e4474c1d693a6ea9ea8120198ed465a245e4ca0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for cfn-resource-timeout 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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