Skip to main content

A package that facilitates working with existing CloudFormation templates in the CDK

Project description

Include CloudFormation templates in the CDK

---

cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


This module contains a set of classes whose goal is to facilitate working with existing CloudFormation templates in the CDK. It can be thought of as an extension of the capabilities of the CfnInclude class.

Basic usage

Assume we have a file my-template.json, that contains the following CloudFormation template:

{
  "Resources": {
    "Bucket": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": "some-bucket-name"
      }
    }
  }
}

It can be included in a CDK application with the following code:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.cloudformation_include as cfn_inc

cfn_template = cfn_inc.CfnInclude(self, "Template",
    template_file="my-template.json"
)

This will add all resources from my-template.json into the CDK application, preserving their original logical IDs from the template file.

Any resource from the included template can be retrieved by referring to it by its logical ID from the template. If you know the class of the CDK object that corresponds to that resource, you can cast the returned object to the correct type:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_s3 as s3

cfn_bucket = cfn_template.get_resource("Bucket")

Any modifications made to that resource will be reflected in the resulting CDK template; for example, the name of the bucket can be changed:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
cfn_bucket.bucket_name = "my-bucket-name"

You can also refer to the resource when defining other constructs, including the higher-level ones (those whose name does not start with Cfn), for example:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_iam as iam

role = iam.Role(self, "Role",
    assumed_by=iam.AnyPrincipal()
)
role.add_to_policy(iam.PolicyStatement(
    actions=["s3:*"],
    resources=[cfn_bucket.attr_arn]
))

If you need, you can also convert the CloudFormation resource to a higher-level resource by importing it by its name:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
bucket = s3.Bucket.from_bucket_name(self, "L2Bucket", cfn_bucket.ref)

Known limitations

This module is still in its early, experimental stage, and so does not implement all features of CloudFormation templates. All items unchecked below are currently not supported.

Ability to retrieve CloudFormation objects from the template:

  • Resources
  • Parameters
  • Conditions
  • Outputs

Resource attributes:

  • Properties
  • Condition
  • DependsOn
  • CreationPolicy
  • UpdatePolicy
  • UpdateReplacePolicy
  • DeletionPolicy
  • Metadata

CloudFormation functions:

  • Ref
  • Fn::GetAtt
  • Fn::Join
  • Fn::If
  • Fn::And
  • Fn::Equals
  • Fn::Not
  • Fn::Or
  • Fn::Base64
  • Fn::Cidr
  • Fn::FindInMap
  • Fn::GetAZs
  • Fn::ImportValue
  • Fn::Select
  • Fn::Split
  • Fn::Sub
  • Fn::Transform

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

aws-cdk.cloudformation-include-1.42.1.tar.gz (152.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_cdk.cloudformation_include-1.42.1-py3-none-any.whl (150.5 kB view details)

Uploaded Python 3

File details

Details for the file aws-cdk.cloudformation-include-1.42.1.tar.gz.

File metadata

  • Download URL: aws-cdk.cloudformation-include-1.42.1.tar.gz
  • Upload date:
  • Size: 152.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.5

File hashes

Hashes for aws-cdk.cloudformation-include-1.42.1.tar.gz
Algorithm Hash digest
SHA256 079acfd679eb28869cbb78e515e3b96fc18b8badba788fca42708fac18d5a66a
MD5 94c0636e8321de28421cc501fc1dfb67
BLAKE2b-256 04d2eee8c2d5f891624b2dea1bf6b697afe28fe5ef964dde98868a83ed890c1e

See more details on using hashes here.

File details

Details for the file aws_cdk.cloudformation_include-1.42.1-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.cloudformation_include-1.42.1-py3-none-any.whl
  • Upload date:
  • Size: 150.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.5

File hashes

Hashes for aws_cdk.cloudformation_include-1.42.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3463e2060e6100de70ef956728ada5feca777a698dc1da768621cfb49d44ac15
MD5 15da19a94dea2376a62c40234bd82213
BLAKE2b-256 cfdb469f06a574a80ae063eb71dfa4078472cfd0b56519ebf3519de3b40f84a8

See more details on using hashes here.

Supported by

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