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.

Filename, size & hash SHA256 hash help File type Python version Upload date
pycfmodel-0.2.8.tar.gz (8.4 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page