Skip to main content

A python model for CloudFormation scripts

Project description

pycfmodel

Build Status 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 Models

  • parameters
  • resources
    • Generic Resource
    • IAM Group
    • IAM Managed Policy
    • IAM role
    • S3 Bucket Policy
    • Security Group Egress
    • Security Group Ingress
    • Security Group
    • SNS Topic Policy
    • SQS Queue Policy
  • properties
    • Policy Document
    • Policy
    • Principal
    • Security Group Egress Property
    • Security Group Ingress Property
    • Statement

Example

import pycfmodel

template = {
  "Resources": {
    "S3Bucket" : {
      "Type" : "AWS::S3::Bucket",
      "Properties" : {
        "BucketName" : "fakebucketfakebucket"
      }
    },

    "S3BucketPolicyWithNotAction": {
      "Type": "AWS::S3::BucketPolicy",
      "Properties": {
        "Bucket": {
          "Ref": "S3Bucket"
        },
        "PolicyDocument": {
          "Statement": [
            {
              "Action": [
                "s3:*"
              ],
              "Effect": "Allow",
              "Resource": "arn:aws:s3:::fakebucketfakebucket/*",
              "Principal": {
                "AWS": "*"
              }
            }
          ]
        }
      }
    }
  }
}

parsed_cf = pycfmodel.parse(template)
for resource in parsed_cf.resources.get("AWS::S3::BucketPolicy", []):
    if resource.policy_document.wildcard_allowed_actions(pattern=r"^(\w*:){0,1}\*$"):
        print(resource.logical_id)

Local Development Commands

make install-dev
make coverage
make test
make freeze

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

pycfmodel-0.2.4.tar.gz (8.1 kB view hashes)

Uploaded Source

Supported by

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