Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Wrapper decorators for building CloudFormation custom resources

Project description


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.


  1. Copy into the directory of your lambda function, which can be done by installing with pip.
  2. Use the cfn_resource.Resource event decorators to decorate your handler like in
  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()

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

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

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

Running Tests

Install and run 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.


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.


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)

Project details

Release history Release notifications

This version
History Node


History Node


History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
cfn_resource_timeout-1.2.0-py2.py3-none-any.whl (6.7 kB) Copy SHA256 hash SHA256 Wheel 2.7 May 3, 2017
cfn-resource-timeout-1.2.0.tar.gz (5.1 kB) Copy SHA256 hash SHA256 Source None May 3, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page