pycfmodel
A python model for Cloud Formation scripts.
pycfmodel makes it easier to work with CloudFormation scripts in Python by creating a model comprised of python objects. Objects have various helper functions which help with performing common tasks related to parsing and inspecting CloudFormation scripts.
pip install pycfmodel
Currently Supported
- AWSTemplateFormatVersion
- Conditions
- Description
- Mappings
- Metadata
- Outputs
- Parameters
- Resources:
- Properties:
- Policy
- Policy Document
- Principal
- Security Group Egress Prop
- Security Group Ingress Prop
- Statement
- Tag
- EC2 VPC Endpoint Policy
- Generic Resource
- IAM Group
- IAM Managed Policy
- IAM Policy
- IAM Role
- IAM User
- KMS Key
- OpenSearch Service (legacy ElasticSearch resource)
- Elasticsearch Domain
- OpenSearch Service
- OpenSearchService Domain
- S3 Bucket
- S3 Bucket Policy
- Security Group
- Security Group Egress
- Security Group Ingress
- SNS Topic Policy
- SQS Queue Policy
- WAFv2 IP Set
- Properties:
- Transform
Example
from pycfmodel import parse
template = {
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {"StarParameter": {"Type": "String", "Default": "*", "Description": "Star Param"}},
"Resources": {
"rootRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"AWS": {"Fn::Sub": "arn:aws:iam::${AWS::AccountId}:root"}},
"Action": ["sts:AssumeRole"],
}
],
},
"Path": "/",
"Policies": [
{
"PolicyName": "root",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": {"Ref": "StarParameter"},
"Resource": {"Ref": "StarParameter"},
}
],
},
}
],
},
}
},
}
model = parse(template).resolve(extra_params={"AWS::AccountId": "123"})
rootRole = model.Resources["rootRole"]
policy = rootRole.Properties.Policies[0]
statement = policy.PolicyDocument.Statement[0]
assert statement.Action == "*"
assert statement.Resource == "*"
assert rootRole.Properties.AssumeRolePolicyDocument.Statement[0].Principal == {"AWS": "arn:aws:iam::123:root"}
Local Development Commands
This project uses uv for dependency management.
make install-dev # Install all development dependencies
make coverage # Run tests with coverage
make test # Run linting and tests
make lock # Update uv.lock file
make lock-upgrade # Upgrade all dependencies and update uv.lock
Updating CloudFormation Actions
If the test tests/test_constants.py::test_cloudformation_actions is failing, it can be resolved by updating the known
AWS Actions:
make install-cloudformation-update
make cloudformation-update
Metadata
Release files for pycfmodel 2.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pycfmodel-2.1.3.tar.gz | 308.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycfmodel-2.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 504.6 kB
Release files / pycfmodel-2.1.3.tar.gz
| Download URL | pycfmodel-2.1.3.tar.gz |
|---|---|
| Size | 308.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f73817033b6b7ce8d0ce29d9c1dd2cea0130836348818fe353c21cf986f8273c
|
|
BLAKE2b-256 checksum How to use checksums |
30fdffe084171d58fa3e2f077cdf2a52402a7d7bb54c0ae4ea8be7b6f3b13faf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycfmodel-2.1.3-py3-none-any.whl
| Download URL | pycfmodel-2.1.3-py3-none-any.whl |
|---|---|
| Size | 196.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a2fa348b6ef3fb201c0218734f962bcc54c6b0ea82d150243c6f4037bcd1540
|
|
BLAKE2b-256 checksum How to use checksums |
74a9c4ba25613d04844a75f75a3a2310c6dc26b7495405f6dcf5e08027287b75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|