Skip to main content

Streamline AWS CloudFormation Custom Resource Management with Python's cfnresponse2

Simplify the management of custom resources in AWS CloudFormation, especially within AWS Lambda environments, using the cfnresponse2 Python package.

Installation

You can effortlessly install the cfnresponse2 package via pip:

pip install cfnresponse2

Alternatively, you have the option to download it directly or upload it to Amazon S3:

import urllib3, sys, os

sys.path.append("/tmp")
raw_url = "https://raw.githubusercontent.com/ggiallo28/cfnresponse/master/cfnresponse/__init__.py"
with open("/tmp/cfnresponse.py", "wb") as f, urllib3.PoolManager() as http:
    f.write(http.request("GET", raw_url).data)

from cfnresponse import register_handler, lambda_handler


@register_handler("create", "update", "delete")
def myfun(event, context):
    return {}

Practical Use Cases

cfnresponse2 is designed with AWS Lambda functions in mind, serving as custom resource handlers in CloudFormation stacks. It simplifies CloudFormation operations such as creating, updating, and deleting custom resources. This empowers you to execute custom logic during stack operations.

For comprehensive examples showcasing effective usage of the cfnresponse2 package, explore the samples directory within the repository. These samples cover various scenarios of custom resource management within CloudFormation.

from cfnresponse import register_handler, lambda_handler

@register_handler("create")
def custom_create(event, context):
    # Your custom logic for handling the 'create' action
    response_data = {"message": "Resource creation successful"}
    return response_data

@register_handler("update")
def custom_update(event, context):
    # Your custom logic for handling the 'update' action
    response_data = {"message": "Resource update successful"}
    return response_data

@register_handler("delete")
def custom_delete(event, context):
    # Your custom logic for handling the 'delete' action
    response_data = {"message": "Resource deletion successful"}
    return response_data

Repository Structure

The project repository is organized as follows:

  • cfnresponse: Houses the __init__.py file, serving as the core of the cfnresponse2 module.
  • LICENSE: Contains licensing information associated with the package.
  • README.md: The document you are currently reading, offering essential instructions for usage.
  • samples: Contains sample Lambda functions that provide practical demonstrations of cfnresponse2 usage. The actual code resides in the repository, not within this README.
  • setup.py: A configuration file for setting up the package.
  • tests: Contains test cases tailored to evaluate the functionality of the cfnresponse2 package.

Important Note

cfnresponse2 maintains compatibility with Amazon Web Services (AWS) cfnresponse module, readily available within Python AWS Lambda environments. You can seamlessly update your code with this package, ensuring a smooth transition without disruptions.

Metadata

Release files for cfnresponse2 1.0.7

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

Source distribution (sdist)

Source distribution for cfnresponse2 1.0.7
File Size Uploaded
cfnresponse2-1.0.7.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cfnresponse2 1.0.7
File Interpreter ABI Platform
cfnresponse2-1.0.7-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 16.5 kB

Release files / cfnresponse2-1.0.7.tar.gz

Download URL cfnresponse2-1.0.7.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8b83bf241fe307eb9445e6460fa97532d90b3620df708d9ecd0d28160fd4e7df
BLAKE2b-256 checksum
How to use checksums
d80817cc185b9d5afbe06dce5eb9b80adefb0795041459623ad8ab2e8eaf3a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release files / cfnresponse2-1.0.7-py2.py3-none-any.whl

Download URL cfnresponse2-1.0.7-py2.py3-none-any.whl
Size 8.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9ae69e51c71a62d450d84f88f335c50e047fecfd25c9c61f6e72eb36a1f9653c
BLAKE2b-256 checksum
How to use checksums
9c4a877a6c43aa6a04d47a42e3bfd5a561ff6de46d23e80d6e6199eac27ea9a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release history Release notifications | RSS feed

This release

1.0.7 This release

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.3

2 release files

1.0.0

2 release files

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