A python model for Cloud Formation scripts
Project description
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
make install-dev
make coverage
make test
make freeze
If the test tests/test_constants.py::test_cloudformation_actions is failing, it can be resolved by updating the known
AWS Actions:
python3 scripts/generate_cloudformation_actions_file.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycfmodel-1.2.0.tar.gz.
File metadata
- Download URL: pycfmodel-1.2.0.tar.gz
- Upload date:
- Size: 155.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42373cdaeaa1f55e0b82b23af724ce3cc5bc1fb5ff91700d94713d80386d5afe
|
|
| MD5 |
3124be0b3e9ec014ef74c7e717e13930
|
|
| BLAKE2b-256 |
371232eb36667d1af57fb07cd25233c94f83760a5e1ff9e162107687bac666a1
|
File details
Details for the file pycfmodel-1.2.0-py3-none-any.whl.
File metadata
- Download URL: pycfmodel-1.2.0-py3-none-any.whl
- Upload date:
- Size: 160.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efd915ca2e39becf5dbbfc405616664e66c8da47d9c8f0d57d981bedb5b91122
|
|
| MD5 |
e9f2ffc1669190e4cd93c3ade36e4d99
|
|
| BLAKE2b-256 |
5a1fd56e67d7dc7a33c8a70ff7ded10fa700987eec46a08584c83a85637153da
|