https://github.com/pplu/cloudformation-loader
Import Python code embedded in CloudFormation Templates without hassle. Helps make your Lambdas testeable
https://github.com/pplu/cloudformation-loader
Last synced: 10 months ago
JSON representation
Import Python code embedded in CloudFormation Templates without hassle. Helps make your Lambdas testeable
- Host: GitHub
- URL: https://github.com/pplu/cloudformation-loader
- Owner: pplu
- License: apache-2.0
- Created: 2025-08-28T15:48:54.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-29T09:50:37.000Z (10 months ago)
- Last Synced: 2025-08-29T13:39:45.141Z (10 months ago)
- Language: Python
- Size: 12.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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 cloudfomation_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