Skip to main content

Import Python code embedded in CloudFormation Templates without hassle. Helps you test your Lambda Functions

Project description

cloudformation-loader

Import Python code embedded in CloudFormation Templates without hassle

Description

When you author Lambda Functions inside CloudFormation templates you often have the choice of inlining the code or maintaining the code externally.

Maintaining the Lambda code separate from the CloudFormation Template forces you to use a solution that packages and uploads the code for you (SAM, CDK, etc). It makes testing very easy, since we can import our Lambda code as any other Python file via imports, but it is often a hassle because you have to have utilities installed in your environment.

Inlining the code is very convenient because you don't have to worry about multiple files or external utilities, but it makes testing almost impossible (since the code is "locked" inside the CloudFormation Template). Until now.

Usage

import cloudformation_loader
cloudformation_loader.import_from_cloudformation('mycloudformation.yaml', 'module_name', 'LambdaLogicalId')

import module_name

# call and use the code inside the Lambda Function
module_name.my_function('test')

# you can even call the handler
module_name.handler({ 'testing': 'me' })

# or use pytest
import pytest
assert module_name.my_function('test') == 42

Contributions

Thanks to Yuriy Kurylyak for ideas and feedback.

The CloudFormation YAML loading code was taken from https://github.com/awslabs/aws-cfn-template-flip

Contributions are more than welcome.

The source code is located here: https://github.com/pplu/cloudformation-loader

Issuses can be opened here: https://github.com/pplu/cloudformation-loader/issues

Author

Jose Luis Martinez Torres (pplusdomain@gmail.com)

Copyright and License

Copyright (c) 2025 by Jose Luis Martinez Torres

This project is Apache-2.0

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

cloudformation_loader-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudformation_loader-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file cloudformation_loader-0.1.0.tar.gz.

File metadata

File hashes

Hashes for cloudformation_loader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 852b05a49417193bf5a8ae6dfc5c3daf1cf1a2811c57e7e5b9f88bd8e8e47296
MD5 c63add55520a79ecb56a09d0192c6e52
BLAKE2b-256 3a1590db38329de70296c8c8f67c4be37be8eb2678d23cf6af8ecc5b16bede39

See more details on using hashes here.

File details

Details for the file cloudformation_loader-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudformation_loader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d6e737b9a900499d11a76719af9a3e566a71f65af3e47c50ccda3901ac01514
MD5 ec1951467b39707a129b2d491a1292ba
BLAKE2b-256 bb826eac1ba5df9c0accb0d49a70424eebae334ad0785c2017a5c8db1f4ddb55

See more details on using hashes here.

Supported by

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