{"id":8855,"library":"aws-cdk-aws-cloudformation","title":"AWS CDK v1 CloudFormation Constructs","description":"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.","status":"maintenance","version":"1.204.0","language":"en","source_language":"en","source_url":"https://github.com/aws/aws-cdk.git","tags":["aws","cdk","cloudformation","infrastructure-as-code","iac","v1"],"install":[{"cmd":"pip install aws-cdk.aws-cloudformation","lang":"bash","label":"Install v1"}],"dependencies":[{"reason":"Core AWS CDK functionality required for any CDK application in v1.","package":"aws-cdk.core","optional":false},{"reason":"Base class for all constructs.","package":"constructs","optional":false},{"reason":"Requires Python 3.7 or newer.","package":"python","optional":false}],"imports":[{"note":"This package is for AWS CDK v1; v2 uses `aws_cdk_lib`.","wrong":"from aws_cdk_lib.aws_cloudformation import CfnStack","symbol":"CfnStack","correct":"from aws_cdk.aws_cloudformation import CfnStack"},{"symbol":"CfnCustomResource","correct":"from aws_cdk.aws_cloudformation import CfnCustomResource"}],"quickstart":{"code":"import os\nfrom aws_cdk import App, Stack, Environment\nfrom aws_cdk.aws_cloudformation import CfnStack\nfrom constructs import Construct\n\nclass MyCfnStackExample(Stack):\n    def __init__(self, scope: Construct, id: str, **kwargs) -> None:\n        super().__init__(scope, id, **kwargs)\n\n        # This construct deploys an existing CloudFormation template from an S3 URL.\n        # Replace with a valid S3 URL to your CloudFormation template.\n        # Ensure the deployment role has permissions to read from this S3 location.\n        template_url = os.environ.get('CFN_TEMPLATE_URL', 'https://s3.amazonaws.com/your-bucket/your-template.yaml')\n        if not template_url.startswith('https://'):\n            print(\"WARNING: CFN_TEMPLATE_URL is not set or invalid. Using a placeholder.\")\n\n        cfn_stack = CfnStack(self, \"MyExistingCloudFormationStack\",\n            template_url=template_url,\n            parameters={\n                \"EnvironmentName\": \"Dev\",\n                \"Project\": \"MyCDKApp\"\n            },\n            tags={\n                \"ManagedBy\": \"CDK\"\n            }\n        )\n\napp = App()\nMyCfnStackExample(app, \"MyCfnStackApp\",\n    env=Environment(account=os.environ.get(\"CDK_DEFAULT_ACCOUNT\"),\n                    region=os.environ.get(\"CDK_DEFAULT_REGION\"))\n)\napp.synth()\n","lang":"python","description":"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."},"warnings":[{"fix":"Plan a migration to AWS CDK v2 by installing `aws-cdk-lib` and updating your code to use the consolidated module imports (e.g., `from aws_cdk_lib import aws_cloudformation`). Refer to the official CDK v1 to v2 migration guide.","message":"AWS CDK v1 (`aws-cdk.aws-cloudformation`) is in maintenance mode. Active development, new features, and most bug fixes are concentrated on AWS CDK v2 (`aws-cdk-lib`). Migrating to v2 is highly recommended as v1 will eventually reach end-of-life.","severity":"breaking","affected_versions":"All v1.x.x versions"},{"fix":"For a higher-level abstraction and simpler custom resource creation, consider using the `CustomResource` construct from `aws_cdk.custom_resources` (part of `aws-cdk.custom-resources` for v1) which handles much of the boilerplate for you.","message":"When using `CfnCustomResource`, you are responsible for providing the full implementation details, including the Lambda function code, execution role, and service token. This is a lower-level construct.","severity":"gotcha","affected_versions":"All v1.x.x versions"},{"fix":"Ensure the CDK deployment role (often provisioned by `cdk bootstrap`) has `s3:GetObject` permissions for the template S3 bucket and all necessary permissions for the resources declared in the referenced CloudFormation template.","message":"The `CfnStack` construct deploys a CloudFormation template. The AWS account and IAM role used for CDK deployment must have permissions to read the `template_url` (if from S3) and to deploy all resources defined within that CloudFormation template.","severity":"gotcha","affected_versions":"All v1.x.x versions"},{"fix":"Prefer using CDK's native constructs where possible. Use `CfnStack` for deploying existing templates or when a specific CloudFormation resource lacks a direct CDK construct. Be mindful of resource logical IDs and potential overwrites if the same resource is defined both natively and via `CfnStack`.","message":"Mixing raw CloudFormation definitions via `CfnStack` with high-level CDK constructs in the same stack can sometimes lead to unexpected behavior or resource ownership conflicts if not carefully managed.","severity":"gotcha","affected_versions":"All v1.x.x versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Either install AWS CDK v2 via `pip install aws-cdk-lib` (and adapt your code) or stick to v1 imports (e.g., `from aws_cdk import core`, `from aws_cdk.aws_cloudformation import ...`).","cause":"You are attempting to use AWS CDK v2 (`aws_cdk_lib`) imports, but only AWS CDK v1 packages like `aws-cdk.aws-cloudformation` are installed.","error":"ModuleNotFoundError: No module named 'aws_cdk_lib'"},{"fix":"For AWS CDK v1, install the package with `pip install aws-cdk.aws-cloudformation`. For AWS CDK v2, the `aws_cloudformation` module is part of `aws_cdk_lib`, so use `from aws_cdk_lib import aws_cloudformation`.","cause":"The `aws-cdk.aws-cloudformation` package is not installed in your Python environment or you are trying to import it in a v2 context without the correct v2 import path.","error":"ModuleNotFoundError: No module named 'aws_cdk.aws_cloudformation'"},{"fix":"Ensure all required properties for the construct are explicitly provided with valid string values. Double-check environment variables or configuration values if they are used to populate properties.","cause":"A required property for a CDK construct, such as `template_url` for `CfnStack`, was not provided or evaluated to `None`.","error":"TypeError: Expected type str, got None"},{"fix":"Verify the S3 URL is correct and publicly accessible, or that your CDK deployment role has `s3:GetObject` permissions for that bucket and object. Ensure the S3 object is a valid CloudFormation template.","cause":"The `template_url` provided to `CfnStack` is either incorrect, inaccessible, or does not point to a well-formed CloudFormation template in an S3 bucket.","error":"jsii.errors.JavaScriptError: Error: Stack 'MyCfnStackApp' cannot be deployed, as its 'templateUrl' does not point to a valid template in S3."}]}