cftdeploy


Namecftdeploy JSON
Version 1.0.7 PyPI version JSON
download
home_pagehttp://github.com/jchrisfarris/cft-deploy
SummaryTools and modules for managing CloudFormation Templates & Stacks
upload_time2023-05-27 21:29:07
maintainer
docs_urlNone
authorChris Farris
requires_python>=3.6
licenseApache License 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cft-deploy
Python module & scripts for managing AWS CloudFormation Stacks

## Rationale

CloudFormation is a valuable tool, but it has some short-comings with the management of stacks via the CLI.

* The number of options and parameters that the `aws cloudformation create-stack` command is pretty large, and when using CLI/SDK you need a consistent way to manage that. Here are the options in the AWS CLI:

```Bash
--stack-name
[--template-body ]
[--template-url ]
[--parameters ]
[--disable-rollback | --no-disable-rollback]
[--timeout-in-minutes ]
[--notification-arns ]
[--capabilities ]
[--resource-types ]
[--role-arn ]
[--on-failure ]
[--stack-policy-body ]
[--stack-policy-url ]
[--tags ]
```

* While stacks can export a value, the exported value's key must be unique in the region. Furthermore you cannot provide the corresponding imported value's key as a parameter. It must be hard-coded in the CFT. As a result you cannot have a single template that works for dev, test & prod that leverages different exported values.
* If a stack exports a value, you are significantly impaired from modifying that stack. AWS puts these protections in place for your own protection, however in some cases you might not want to have to delete a dependent stack before modifying the exporting stack.
* ```aws cloudformation create-stack``` is something of a fire & forget operation. Yes, you can use the CLI to setup a waiter. But lets face it, that's pretty complex.


cft-deploy is designed to help with some of these issues.

* cft-deploy uses the concept of a **manifest file** to store all of the parameters and stack options. These manifest files are in yaml and can be kept in revision control
* cft-deploy can go lookup parameters from another stack's parameters, resources or outputs. This is useful for example, if you have a template that deploys a VPC and you need to reference the vpcId, subnetIds and security groups in a template that deploys an instance or rds.
* cft-deploy's parameter lookup doesn't require regionally scoped global variables. The manifest file can contain the name of the stack you want to reference
* cft-deploy will display the status of the stack creation & update similar to how the progress is displayed in the AWS console.
* cft-deploy supports [stack policies](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/protect-stack-resources.html#stack-policy-reference) in the manifest file.
* cft-deploy can generate manifest files from templates (and in the future will generate manifest files from existing stacks)


## Installation

For testing, the install process is
```bash
pip install -e .
```

For production usage, you can install cft-deploy from PyPi. (Not implemented just yet)

## Usage

### Manifest Files

### Scripts

* **cft-validate** - Will validate a template with the AWS CloudFormation service
* **cft-upload** - Will upload a CFT to S3, which is required if the template is over a certian size
* **cft-generate-manifest** - Will take a local or s3-hosted template, and generate a manifest file
* **cft-validate-manifest** - Will perform all of the parameter substitutions and validate that dependencies exist
* **cft-deploy** - Will take the manifest (and optional command-line params) and create or update the stack (providing a tail -f like experience of the events)
* **cft-delete** - Will delete the specified stack (providing a tail -f like experience of the deletion events)


### Python Module

The Python Modules consists of three main classes. All the classes support a Session being passed in which would support cross-account role assumption (among other things).

All modules use the python logger for debug and informational events. These can be overridden as needed.

#### CFTemplate
CFTemplate represents a CloudFormation Template

    class CFTemplate(builtins.object)
     |  CFTemplate(template_body, filename=None, s3url=None, session=None)
     |
     |  Class to represent a CloudFormation Template
     |
     |  Methods defined here:
     |
     |  __init__(self, template_body, filename=None, s3url=None, session=None)
     |      Constructs a CFTemplate from the template_body (json or yaml).
     |
     |  diff(self, other_template)
     |      prints out the differences between this template and another one.
     |
     |  generate_manifest(self, manifest_file_name, substitutions=None)
     |      Generates a stub manifest file for this template and writes it to manifest_file_name.
     |      If substitutions are specified, these are populated into the stub manifest file.
     |
     |  upload(self, bucket, object_key)
     |      Upload the template to S3.
     |
     |  validate(self)
     |      Validate the template's syntax by sending to CloudFormation Service. Returns json from AWS.
     |
     |  ----------------------------------------------------------------------
     |  Class methods defined here:
     |
     |  download(bucket, object_key, session=None)
     |      Downloads the template from S3 and then initialize.
     |
     |  parse_s3_url(s3url)
     |      Parse an s3url (s3://bucket/object_key) and return the bucket and object_key
     |
     |  read(filename, session=None)
     |      Read the template from filename and then initialize.

The exception *CFTemplateTooLargeError* is defined where the template must be uploaded to S3 before the AWS CloudFormation service can use it.

#### CFManifest

    class CFManifest(builtins.object)
     |  CFManifest(manifest_filename, session=None)
     |
     |  Class to represent a CloudFormation Template
     |
     |  Methods defined here:
     |
     |  __init__(self, manifest_filename, session=None)
     |      Constructs a CFManifest from the manifest file.
     |
     |  build_cft_payload(self)
     |      Generate the CFT Payload
     |
     |  create_stack(self, override=None)
     |      Creates a Stack based on this manifest.
     |
     |  estimate_cost(self)
     |      Return a url to the simple monthly cost estimator for this template / parameter set.
     |
     |  fetch_parameters(self, override=None)
     |      Based on the manifest's Sourced Parameters, find all the parameters and populate them.
     |
     |  override_option(self, key, value)
     |      If options are passed in on he command line, these will override the manifest file's value
     |
     |  validate(self, override=None)
     |      Validate the template's syntax by sending to CloudFormation Service. Returns json from AWS.

#### CFStack

    class CFStack(builtins.object)
     |  CFStack(stack_name, region, session=None)
     |
     |  Class to represent a CloudFormation Template
     |
     |  Methods defined here:
     |
     |  __init__(self, stack_name, region, session=None)
     |      Constructs a CFTemplate from the template_body (json or yaml).
     |
     |  create_changeset(self, changeset_name)
     |      Trigger the creation of the changeset.
     |
     |  delete(self)
     |      Deletes this stack.
     |
     |  describe_changeset(self, changeset_name)
     |      Get the details of changes from a previously created changeset.
     |
     |  detect_drift(self)
     |      Triggers Drift Detection for this stack.
     |
     |  get(self)
     |      Fetch the latest set of data for this stack from AWS and update properties of the instance.
     |
     |  get_outputs(self)
     |      Return a dict of each output of this stack.
     |
     |  get_parameters(self)
     |      Return a dict of each parameter to this stack.
     |
     |  get_resources(self)
     |      Return all the PhysicalResourceIds for each LogicalId in the template
     |
     |  get_stack_events(self, last_event_id=None)
     |      Return all stack events since last_event_id.
     |
     |  get_status(self)
     |      Fetch the value of StackStatus from AWS CF API for this stack
     |
     |  get_template(self)
     |      Return as a CFTemplate the current template for this stack.
     |
     |  list_changesets(self)
     |      List all active changesets for this stack.
     |
     |  update(self, manifest)
     |      Updates a Stack based on this manifest.

Exceptions defined for this class are
* *CFStackDoesNotExistError* - which has an attribute of stackname

## Roadmap

1. Support for CloudFormation Changesets, so you can see what an update will do to the stack before you execute it.
3. Support for CloudFormation drift detection.
4. Support for generating a unix-like diff of an existing stack's template and a proposed update to the template.
2. Support for generating Manifest files from existing stacks.


            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/jchrisfarris/cft-deploy",
    "name": "cftdeploy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Chris Farris",
    "author_email": "chris@room17.com",
    "download_url": "https://files.pythonhosted.org/packages/3d/af/f56d3d48fbdf0e3acd5953990ccd1b04c727e3f7d4fc5a2ecb4208b92c1e/cftdeploy-1.0.7.tar.gz",
    "platform": null,
    "description": "# cft-deploy\nPython module & scripts for managing AWS CloudFormation Stacks\n\n## Rationale\n\nCloudFormation is a valuable tool, but it has some short-comings with the management of stacks via the CLI.\n\n* The number of options and parameters that the `aws cloudformation create-stack` command is pretty large, and when using CLI/SDK you need a consistent way to manage that. Here are the options in the AWS CLI:\n\n```Bash\n--stack-name\n[--template-body ]\n[--template-url ]\n[--parameters ]\n[--disable-rollback | --no-disable-rollback]\n[--timeout-in-minutes ]\n[--notification-arns ]\n[--capabilities ]\n[--resource-types ]\n[--role-arn ]\n[--on-failure ]\n[--stack-policy-body ]\n[--stack-policy-url ]\n[--tags ]\n```\n\n* While stacks can export a value, the exported value's key must be unique in the region. Furthermore you cannot provide the corresponding imported value's key as a parameter. It must be hard-coded in the CFT. As a result you cannot have a single template that works for dev, test & prod that leverages different exported values.\n* If a stack exports a value, you are significantly impaired from modifying that stack. AWS puts these protections in place for your own protection, however in some cases you might not want to have to delete a dependent stack before modifying the exporting stack.\n* ```aws cloudformation create-stack``` is something of a fire & forget operation. Yes, you can use the CLI to setup a waiter. But lets face it, that's pretty complex.\n\n\ncft-deploy is designed to help with some of these issues.\n\n* cft-deploy uses the concept of a **manifest file** to store all of the parameters and stack options. These manifest files are in yaml and can be kept in revision control\n* cft-deploy can go lookup parameters from another stack's parameters, resources or outputs. This is useful for example, if you have a template that deploys a VPC and you need to reference the vpcId, subnetIds and security groups in a template that deploys an instance or rds.\n* cft-deploy's parameter lookup doesn't require regionally scoped global variables. The manifest file can contain the name of the stack you want to reference\n* cft-deploy will display the status of the stack creation & update similar to how the progress is displayed in the AWS console.\n* cft-deploy supports [stack policies](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/protect-stack-resources.html#stack-policy-reference) in the manifest file.\n* cft-deploy can generate manifest files from templates (and in the future will generate manifest files from existing stacks)\n\n\n## Installation\n\nFor testing, the install process is\n```bash\npip install -e .\n```\n\nFor production usage, you can install cft-deploy from PyPi. (Not implemented just yet)\n\n## Usage\n\n### Manifest Files\n\n### Scripts\n\n* **cft-validate** - Will validate a template with the AWS CloudFormation service\n* **cft-upload** - Will upload a CFT to S3, which is required if the template is over a certian size\n* **cft-generate-manifest** - Will take a local or s3-hosted template, and generate a manifest file\n* **cft-validate-manifest** - Will perform all of the parameter substitutions and validate that dependencies exist\n* **cft-deploy** - Will take the manifest (and optional command-line params) and create or update the stack (providing a tail -f like experience of the events)\n* **cft-delete** - Will delete the specified stack (providing a tail -f like experience of the deletion events)\n\n\n### Python Module\n\nThe Python Modules consists of three main classes. All the classes support a Session being passed in which would support cross-account role assumption (among other things).\n\nAll modules use the python logger for debug and informational events. These can be overridden as needed.\n\n#### CFTemplate\nCFTemplate represents a CloudFormation Template\n\n    class CFTemplate(builtins.object)\n     |  CFTemplate(template_body, filename=None, s3url=None, session=None)\n     |\n     |  Class to represent a CloudFormation Template\n     |\n     |  Methods defined here:\n     |\n     |  __init__(self, template_body, filename=None, s3url=None, session=None)\n     |      Constructs a CFTemplate from the template_body (json or yaml).\n     |\n     |  diff(self, other_template)\n     |      prints out the differences between this template and another one.\n     |\n     |  generate_manifest(self, manifest_file_name, substitutions=None)\n     |      Generates a stub manifest file for this template and writes it to manifest_file_name.\n     |      If substitutions are specified, these are populated into the stub manifest file.\n     |\n     |  upload(self, bucket, object_key)\n     |      Upload the template to S3.\n     |\n     |  validate(self)\n     |      Validate the template's syntax by sending to CloudFormation Service. Returns json from AWS.\n     |\n     |  ----------------------------------------------------------------------\n     |  Class methods defined here:\n     |\n     |  download(bucket, object_key, session=None)\n     |      Downloads the template from S3 and then initialize.\n     |\n     |  parse_s3_url(s3url)\n     |      Parse an s3url (s3://bucket/object_key) and return the bucket and object_key\n     |\n     |  read(filename, session=None)\n     |      Read the template from filename and then initialize.\n\nThe exception *CFTemplateTooLargeError* is defined where the template must be uploaded to S3 before the AWS CloudFormation service can use it.\n\n#### CFManifest\n\n    class CFManifest(builtins.object)\n     |  CFManifest(manifest_filename, session=None)\n     |\n     |  Class to represent a CloudFormation Template\n     |\n     |  Methods defined here:\n     |\n     |  __init__(self, manifest_filename, session=None)\n     |      Constructs a CFManifest from the manifest file.\n     |\n     |  build_cft_payload(self)\n     |      Generate the CFT Payload\n     |\n     |  create_stack(self, override=None)\n     |      Creates a Stack based on this manifest.\n     |\n     |  estimate_cost(self)\n     |      Return a url to the simple monthly cost estimator for this template / parameter set.\n     |\n     |  fetch_parameters(self, override=None)\n     |      Based on the manifest's Sourced Parameters, find all the parameters and populate them.\n     |\n     |  override_option(self, key, value)\n     |      If options are passed in on he command line, these will override the manifest file's value\n     |\n     |  validate(self, override=None)\n     |      Validate the template's syntax by sending to CloudFormation Service. Returns json from AWS.\n\n#### CFStack\n\n    class CFStack(builtins.object)\n     |  CFStack(stack_name, region, session=None)\n     |\n     |  Class to represent a CloudFormation Template\n     |\n     |  Methods defined here:\n     |\n     |  __init__(self, stack_name, region, session=None)\n     |      Constructs a CFTemplate from the template_body (json or yaml).\n     |\n     |  create_changeset(self, changeset_name)\n     |      Trigger the creation of the changeset.\n     |\n     |  delete(self)\n     |      Deletes this stack.\n     |\n     |  describe_changeset(self, changeset_name)\n     |      Get the details of changes from a previously created changeset.\n     |\n     |  detect_drift(self)\n     |      Triggers Drift Detection for this stack.\n     |\n     |  get(self)\n     |      Fetch the latest set of data for this stack from AWS and update properties of the instance.\n     |\n     |  get_outputs(self)\n     |      Return a dict of each output of this stack.\n     |\n     |  get_parameters(self)\n     |      Return a dict of each parameter to this stack.\n     |\n     |  get_resources(self)\n     |      Return all the PhysicalResourceIds for each LogicalId in the template\n     |\n     |  get_stack_events(self, last_event_id=None)\n     |      Return all stack events since last_event_id.\n     |\n     |  get_status(self)\n     |      Fetch the value of StackStatus from AWS CF API for this stack\n     |\n     |  get_template(self)\n     |      Return as a CFTemplate the current template for this stack.\n     |\n     |  list_changesets(self)\n     |      List all active changesets for this stack.\n     |\n     |  update(self, manifest)\n     |      Updates a Stack based on this manifest.\n\nExceptions defined for this class are\n* *CFStackDoesNotExistError* - which has an attribute of stackname\n\n## Roadmap\n\n1. Support for CloudFormation Changesets, so you can see what an update will do to the stack before you execute it.\n3. Support for CloudFormation drift detection.\n4. Support for generating a unix-like diff of an existing stack's template and a proposed update to the template.\n2. Support for generating Manifest files from existing stacks.\n\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Tools and modules for managing CloudFormation Templates & Stacks",
    "version": "1.0.7",
    "project_urls": {
        "Homepage": "http://github.com/jchrisfarris/cft-deploy"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "528c069a2c9b25d3a97985feaabd83f780a2118f70d88e665113204cb1c00095",
                "md5": "27890b334c220c68e51cff35e6f411c2",
                "sha256": "f4cb72bc0ed3214131009699e0952f533aa885be25f18065d3830e95d49c6f60"
            },
            "downloads": -1,
            "filename": "cftdeploy-1.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "27890b334c220c68e51cff35e6f411c2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 23253,
            "upload_time": "2023-05-27T21:29:05",
            "upload_time_iso_8601": "2023-05-27T21:29:05.381314Z",
            "url": "https://files.pythonhosted.org/packages/52/8c/069a2c9b25d3a97985feaabd83f780a2118f70d88e665113204cb1c00095/cftdeploy-1.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3daff56d3d48fbdf0e3acd5953990ccd1b04c727e3f7d4fc5a2ecb4208b92c1e",
                "md5": "1a2770dd5bcd8376e64358fd1b437981",
                "sha256": "176ba750f984ac531c225836c67e55dba587a2825def2f46b002e8ade2616fe0"
            },
            "downloads": -1,
            "filename": "cftdeploy-1.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "1a2770dd5bcd8376e64358fd1b437981",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 22307,
            "upload_time": "2023-05-27T21:29:07",
            "upload_time_iso_8601": "2023-05-27T21:29:07.000840Z",
            "url": "https://files.pythonhosted.org/packages/3d/af/f56d3d48fbdf0e3acd5953990ccd1b04c727e3f7d4fc5a2ecb4208b92c1e/cftdeploy-1.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-27 21:29:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jchrisfarris",
    "github_project": "cft-deploy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cftdeploy"
}
        
Elapsed time: 0.06909s