AWS CDK CX-API

2.250.0 · active · verified Thu Apr 16

The `aws-cdk-cx-api` library is a core component of the AWS Cloud Development Kit (CDK), defining the Cloud Executable protocol. It provides interfaces and classes for working with Cloud Assemblies, which are the synthesized artifacts produced by CDK applications. These assemblies contain the CloudFormation templates, assets, and metadata required for deployment. This library is part of CDK v2 and is currently at version 2.250.0, with frequent updates tied to the main CDK release cycle.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load and inspect a synthesized AWS CDK Cloud Assembly. It assumes a `cdk.out` directory has been created by running `cdk synth` in a CDK project. It then prints details about the assembly, including its stacks and artifacts. An alternative path is provided to create an empty assembly programmatically if no `cdk.out` is available.

import os
from aws_cdk.cx_api import CloudAssembly, CloudAssemblyBuilder

# Assuming 'cdk.out' exists in the current directory, typically created by 'cdk synth'.
assembly_path = "./cdk.out"

if os.path.isdir(assembly_path):
    print(f"Loading Cloud Assembly from: {assembly_path}")
    try:
        assembly = CloudAssembly(directory=assembly_path)
        print(f"Assembly ID: {assembly.id}")
        print(f"Version: {assembly.version}")
        print("Found stacks:")
        for stack in assembly.stacks:
            print(f"- {stack.stack_name} (Env: {stack.environment.name})")
        print("Artifacts:")
        for artifact in assembly.artifacts:
            print(f"- {artifact.id} (Type: {type(artifact).__name__})")
    except Exception as e:
        print(f"Error loading Cloud Assembly: {e}")
        print("Ensure 'cdk synth' was run successfully and 'cdk.out' is valid.")
else:
    print(f"Directory '{assembly_path}' not found. Please run 'cdk synth' in a CDK project first.")
    print("Alternatively, you can create an empty assembly programmatically:")
    builder = CloudAssemblyBuilder(outdir="temp_cdk_out")
    builder.build()
    print("Created empty assembly in 'temp_cdk_out'.")
    # os.system("rm -rf temp_cdk_out") # Uncomment to clean up automatically

view raw JSON →