Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

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.

## Usage

1. Copy `` into the directory of your lambda function
1. Use the `cfn_resource.Resource` event decorators to decorate your handler
like in ``
1. 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][rsrc]. For more on the requests you may receive, see
[this document][reqdocs]

"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][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"}

## Running Tests

To run the tests locally, you need Python 2.7 and `pip`. Ideally, you should
use a virtualenv.

$ pip install -r test-requirements.txt
$ py.test

The tests use `mock` and `py.test` 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.

Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cfn_resource-0.2.3.tar.gz (4.9 kB) Copy SHA256 Checksum SHA256 Source Jun 20, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting