Metadata-Version: 2.1
Name: aws-cdk.cloudformation-include
Version: 1.56.0
Summary: A package that facilitates working with existing CloudFormation templates in the CDK
Home-page: https://github.com/aws/aws-cdk
Author: Amazon Web Services
License: Apache-2.0
Project-URL: Source, https://github.com/aws/aws-cdk.git
Description: # Include CloudFormation templates in the CDK
        
        <!--BEGIN STABILITY BANNER-->---
        
        
        ![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
        
        > 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](https://semver.org/) 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.
        
        ---
        <!--END STABILITY BANNER-->
        
        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](../@aws-cdk/core/lib/cfn-include.ts).
        
        ## Basic usage
        
        Assume we have a file with an existing template. It could be in JSON format, in a file `my-template.json`:
        
        ```json
        {
          "Resources": {
            "Bucket": {
              "Type": "AWS::S3::Bucket",
              "Properties": {
                "BucketName": "some-bucket-name"
              }
            }
          }
        }
        ```
        
        Or it could by in YAML format, in a file `my-template.yaml`:
        
        ```yaml
        Resources:
          Bucket:
            Type: AWS::S3::Bucket
            Properties:
              BucketName: some-bucket-name
        ```
        
        It can be included in a CDK application with the following code:
        
        ```python
        # 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"
        )
        ```
        
        Or, if our template is YAML, we can use
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        cfn_template = cfn_inc.CfnInclude(self, "Template",
            template_file="my-template.yaml"
        )
        ```
        
        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:
        
        ```python
        # 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:
        
        ```python
        # 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:
        
        ```python
        # 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:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        bucket = s3.Bucket.from_bucket_name(self, "L2Bucket", cfn_bucket.ref)
        ```
        
        Note that [Custom Resources](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html)
        will be of type CfnResource, and hence won't need to be casted.
        This holds for any resource that isn't in the CloudFormation schema.
        
        ## Parameters
        
        If your template uses [CloudFormation Parameters] (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html),
        you can retrieve them from your template:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        import aws_cdk.core as core
        
        param = cfn_template.get_parameter("MyParameter")
        ```
        
        The `CfnParameter` object is mutable,
        and any changes you make to it will be reflected in the resulting template:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        param.default = "MyDefault"
        ```
        
        ## Conditions
        
        If your template uses [CloudFormation Conditions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html),
        you can retrieve them from your template:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        import aws_cdk.core as core
        
        condition = cfn_template.get_condition("MyCondition")
        ```
        
        The `CfnCondition` object is mutable,
        and any changes you make to it will be reflected in the resulting template:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        condition.expression = core.Fn.condition_equals(1, 2)
        ```
        
        ## Outputs
        
        If your template uses [CloudFormation Outputs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html),
        you can retrieve them from your template:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        import aws_cdk.core as core
        
        output = cfn_template.get_output("MyOutput")
        ```
        
        The `CfnOutput` object is mutable,
        and any changes you make to it will be reflected in the resulting template:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        output.value = cfn_bucket.attr_arn
        ```
        
        ## Nested Stacks
        
        This module also support templates that use [nested stacks](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-nested-stacks.html).
        
        For example, if you have the following parent template:
        
        ```json
        {
          "Resources": {
            "ChildStack": {
              "Type": "AWS::CloudFormation::Stack",
              "Properties": {
                "TemplateURL": "https://my-s3-template-source.s3.amazonaws.com/child-import-stack.json"
              }
            }
          }
        }
        ```
        
        where the child template pointed to by `https://my-s3-template-source.s3.amazonaws.com/child-import-stack.json` is:
        
        ```json
        {
          "Resources": {
            "MyBucket": {
              "Type": "AWS::S3::Bucket"
              }
            }
          }
        }
        ```
        
        You can include both the parent stack and the nested stack in your CDK Application as follows:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        parent_template = inc.CfnInclude(stack, "ParentStack",
            template_file="path/to/my-parent-template.json",
            nested_stacks={
                "ChildStack": {
                    "template_file": "path/to/my-nested-template.json"
                }
            }
        )
        ```
        
        Now you can access the ChildStack nested stack and included template with:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        included_child_stack = parent_template.get_nested_stack("ChildStack")
        child_stack = included_child_stack.stack
        child_stack_template = included_child_stack.included_template
        ```
        
        Now you can reference resources from `ChildStack` and modify them like any other included template:
        
        ```python
        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        bucket = child_stack_template.get_resource("MyBucket")
        bucket.bucket_name = "my-new-bucket-name"
        
        bucket_read_role = iam.Role(child_stack, "MyRole",
            assumed_by=iam.AccountRootPrincipal()
        )
        
        bucket_read_role.add_to_policy(iam.PolicyStatement(
            actions=["s3:GetObject*", "s3:GetBucket*", "s3:List*"
            ],
            resources=[bucket.attr_arn]
        ))
        ```
        
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: JavaScript
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Typing :: Typed
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved
Requires-Python: >=3.6
Description-Content-Type: text/markdown
