A python model for CloudFormation 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
- Generic Resource
- IAM Group
- IAM Managed Policy
- IAM Policy
- IAM Role
- IAM User
- KMS Key
- S3 Bucket Policy
- Security Group
- Security Group Egress
- Security Group Ingress
- SNS Topic Policy
- SQS Queue Policy
- 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
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
pycfmodel-0.8.0.tar.gz
(66.6 kB
view hashes)
Built Distribution
pycfmodel-0.8.0-py3-none-any.whl
(86.2 kB
view hashes)
Close
Hashes for pycfmodel-0.8.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf7b997c68cb6d576127255f9a077487a82cc7f65a69dc18a0cf6008dc44cb47 |
|
MD5 | 9ba7ea6a0899cf09902100d157d037ec |
|
BLAKE2b-256 | ec02f5ac649fa1fee76c8cde9f5235a1ecc1207b62c407bb72c3749b1e715f84 |