Pulumi CDK Conversion Tool (cdk2pulumi)
This tool plugin converts AWS CDK Cloud Assemblies to Pulumi YAML programs.
Prerequisites
- The tool must be installed:
pulumi plugin install tool cdk2pulumi - All commands run through the Pulumi CLI using:
pulumi plugin run cdk2pulumi -- <args> - A CDK Cloud Assembly (typically in
cdk.outdirectory) must exist for conversion operations
Commands
1. Convert CDK Assembly to Pulumi YAML
Converts a CDK Cloud Assembly to a Pulumi YAML program (Pulumi.yaml) with an accompanying conversion report (Pulumi.yaml.report.json).
Basic conversion:
pulumi plugin run cdk2pulumi -- --assembly path/to/cdk.outRequired flags:
--assembly: Path to the synthesized CDK Cloud Assembly (typicallycdk.outdirectory). By default this will convert the entire CDK application (i.e. all stacks and stages)
Optional flags:
--stacks: Comma separated list of CDK Stacks to convert--stage: Filter conversion to a specific CDK Stage--skip-custom: Skip converting CDK custom resources
Important Notes:
- Cross-stack references in partially converted stacks become config placeholders:
${external.<stack>.<output>} - Set these with:
pulumi config set external.<stack>.<output> <value>before deployment - CDK custom resources are rewritten to
aws-native:cloudformation:CustomResourceEmulator - The generated code will use the original CDK logical IDS. DO NOT update these otherwise automated import will FAIL
Common Workflows
Converting a CDK Application to Pulumi
Synthesize the CDK app to generate the Cloud Assembly:
cdk synthConvert the assembly to Pulumi YAML:
pulumi plugin run cdk2pulumi -- --assembly cdk.outReview the conversion report at
Pulumi.yaml.report.jsonto identify any resources that didn't convert 1:1Set any required config for cross-stack references:
pulumi config set external.<stack>.<output> <value>Convert the Pulumi YAML program to the target language:
pulumi convert --from yaml --generate-only --language typescript --out ./generated-programNOTE: after converting to another language you need to remove or rename the
Pulumi.yamlfile, otherwise it will still be treated as the main applicationPreview the Pulumi program:
pulumi preview
Tips for Running
- Always use
--to separate Pulumi CLI arguments from plugin arguments - The
--assemblyflag expects a directory path (typicallycdk.out), not a file - When converting specific stacks, use comma-separated names without spaces:
--stacks Stack1,Stack2 - For multi-stage CDK apps, use
--stage <name>to target nested assemblies - The tool outputs to
Pulumi.yamlby default; use--outto specify a different location