AWS CDK v1 CloudFormation Constructs

1.204.0 · maintenance · verified Thu Apr 16

The `aws-cdk.aws-cloudformation` library provides AWS CDK v1 constructs for interacting with AWS CloudFormation, allowing users to define CloudFormation stacks, custom resources, and stack sets in Python. While functional, version 1.204.0 is part of AWS CDK v1 which is now in maintenance mode, with active development focused on AWS CDK v2 (`aws-cdk-lib`). It receives critical bug fixes but no new features, with releases aligning with the broader AWS CDK v1 maintenance cycle.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `aws_cdk.aws_cloudformation.CfnStack` to deploy an existing CloudFormation template from an S3 URL. It sets up a basic AWS CDK v1 application, defines a stack, and then includes a `CfnStack` construct. For a real deployment, ensure `CFN_TEMPLATE_URL`, `CDK_DEFAULT_ACCOUNT`, and `CDK_DEFAULT_REGION` environment variables are set.

import os
from aws_cdk import App, Stack, Environment
from aws_cdk.aws_cloudformation import CfnStack
from constructs import Construct

class MyCfnStackExample(Stack):
    def __init__(self, scope: Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # This construct deploys an existing CloudFormation template from an S3 URL.
        # Replace with a valid S3 URL to your CloudFormation template.
        # Ensure the deployment role has permissions to read from this S3 location.
        template_url = os.environ.get('CFN_TEMPLATE_URL', 'https://s3.amazonaws.com/your-bucket/your-template.yaml')
        if not template_url.startswith('https://'):
            print("WARNING: CFN_TEMPLATE_URL is not set or invalid. Using a placeholder.")

        cfn_stack = CfnStack(self, "MyExistingCloudFormationStack",
            template_url=template_url,
            parameters={
                "EnvironmentName": "Dev",
                "Project": "MyCDKApp"
            },
            tags={
                "ManagedBy": "CDK"
            }
        )

app = App()
MyCfnStackExample(app, "MyCfnStackApp",
    env=Environment(account=os.environ.get("CDK_DEFAULT_ACCOUNT"),
                    region=os.environ.get("CDK_DEFAULT_REGION"))
)
app.synth()

view raw JSON →