Generated banner for Pulumi Cdk To Pulumi
Generated logo for Pulumi Cdk To Pulumi

Pulumi Cdk To Pulumi

PulumiOfficialPublished by Pulumi

  • Skill
  • Workflow
  • Cloud and DevOps
  • Apache-2.0
  • No issues found

From the author

Load this skill when a user wants to migrate, convert, port, translate, or move an AWS CDK application (including CDK stacks, constructs, or CloudFormation-synthesized templates) to Pulumi. Phrases such as "convert CDK to Pulumi", "migrate CDK app", "port CDK stacks", "replace CDK with Pulumi", "stop using CDK". Do NOT load for general CDK questions, CDK-only help, or CDK vs Pulumi comparisons where no migration is requested.
— the description by Pulumi

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a systematic, step-by-step procedure for converting AWS CDK applications into Pulumi programs. It covers the entire lifecycle of a migration, including environment verification, CDK synthesis, resource inventory, code conversion, handling of custom resources and assets, and optional resource import. The skill ensures that the resulting Pulumi code is structurally valid and provides a comprehensive migration report suitable for pull requests.

What it does

  • Verifies AWS credentials and environment configurations for accurate CDK synthesis.
  • Analyzes CDK stacks and builds a detailed resource inventory from CloudFormation.
  • Performs automated code conversion from CDK constructs to Pulumi resources.
  • Provides specific migration strategies for Lambda-backed custom resources.
  • Identifies and maps deployment assets and bundling requirements to Pulumi patterns.
  • Generates a formal migration report including resource mappings and validation steps.

When to use it

  • When you need to migrate an existing AWS CDK application to Pulumi.
  • When you want to port CDK stacks or constructs to a Pulumi-managed infrastructure.
  • When you are looking to replace CDK with Pulumi for better infrastructure management.
  • When you need to translate synthesized CloudFormation templates into Pulumi code.

Advantages

  • Ensures complete resource coverage by mapping every CloudFormation resource.
  • Provides clear strategies for handling complex CDK-specific patterns like custom resources.
  • Offers guidance on managing build-time assets and bundling within the Pulumi lifecycle.
  • Produces a professional, PR-ready migration report for team transparency.
  • Includes automated import workflows to bring existing infrastructure under Pulumi management.

Usage examples

“Convert my existing AWS CDK application to Pulumi.”
The agent will initiate the information gathering phase, verify your AWS credentials, synthesize the CDK project, and begin the conversion process.
“I want to port my CDK stacks to Pulumi, how do I start?”
The agent will guide you through the migration workflow, starting with identifying your CDK stacks and environments to ensure a successful transition.
“How do I handle my CDK custom resources when moving to Pulumi?”
The agent will analyze your custom resources and provide a strategy to either replace them with native Pulumi resources or use the CustomResourceEmulator.
“Can you help me migrate my CDK app and import the existing resources?”
The agent will perform the code conversion and then guide you through the automated import process to ensure your live infrastructure is managed by Pulumi.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/pulumi/pulumi-cdk-to-pulumi/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip pulumi-cdk-to-pulumi.zip -d .agents/skills

Documentation by Pulumi

CRITICAL SUCCESS REQUIREMENTS

The migration output MUST meet all of the following:

  1. Complete Resource Coverage

    • Every CloudFormation resource synthesized by CDK MUST:

      • Be represented in the Pulumi program OR

      • Be explicitly justified in the final report.

  2. Successful Deployment

    • The produced Pulumi program must be structurally valid and capable of a successful pulumi up (assuming proper config).

  3. Final Migration Report

    • Always output a formal migration report suitable for a Pull Request.

    • Include:

      • CDK → Pulumi resource mapping

      • Provider decisions (aws-native vs aws)

      • Behavioral differences

      • Missing or manually required steps

      • Validation instructions

WHEN INFORMATION IS MISSING

If a user-provided CDK project is incomplete, ambiguous, or missing artifacts (such as cdk.out), ask targeted questions before generating Pulumi code.

MIGRATION WORKFLOW

Follow this workflow exactly and in this order:

1. INFORMATION GATHERING
1.1 Verify AWS Credentials (ESC)

Running AWS commands (e.g., aws cloudformation list-stack-resources) and CDK commands (e.g. cdk synth) requires credentials loaded via Pulumi ESC.

  • If the user has already provided an ESC environment, use it.

  • If no ESC environment is specified, ask the user which ESC environment to use before proceeding with AWS commands.

You MUST confirm the AWS region with the user. The cdk synth results may be incorrect if ran with the wrong AWS Region.

1.2 Synthesize CDK

Run/inspect:

npx cdk synth --quiet
  • ALWAYS run synth with --quiet to prevent the template from being output on stdout.

If failing, inspect cdk.json or package.json for custom synth behavior.

1.3 Identify CDK Stacks & Environments

Read cdk.out/manifest.json:

jq '.artifacts | to_entries | map(select(.value.type == "aws:cloudformation:stack") | {displayName: .key, environment: .value.environment}) | .[]' cdk.out/manifest.json

Example output:

{
  "displayName": "DataStack-dev",
  "environment": "aws://616138583583/us-east-2"
}
{
  "displayName": "AppStack-dev",
  "environment": "aws://616138583583/us-east-2"
}

In the Pulumi stack you create you MUST set both the aws:region and aws-native:region config variables. For example:

pulumi config set aws-native:region us-east-2 --stack dev
pulumi config set aws:region us-east-2 --stack dev
1.4 Build Resource Inventory

For each stack:

aws cloudformation list-stack-resources \
  --region <region> \
  --stack-name <stack> \
  --output json
1.5 Analyze CDK Structure

Extract:

  • Environment-specific conditionals

  • Stack dependencies & cross-stack references

  • Runtime config (context/env vars)

  • Construct types (L1, L2, L3)

2. CODE CONVERSION (CDK → PULUMI)
  • Perform the initial conversion using the cdk2pulumi tool. Follow cdk-convert.md to perform the conversion.

  • Read the conversion report and fill in any gaps. For example, if the conversion fails to convert a resource you have to convert it manually yourself.

2.1 Custom Resources Handling

CDK uses Lambda-backed Custom Resources for functionality not available in CloudFormation. In synthesized CloudFormation, these appear as:

  • Resource type: AWS::CloudFormation::CustomResource or Custom::<name>

  • Metadata contains aws:cdk:path with the handler name (e.g., aws-s3/auto-delete-objects-handler)

Default behavior: cdk2pulumi rewrites custom resources to aws-native:cloudformation:CustomResourceEmulator, which invokes the original Lambda. This works but has tradeoffs (Lambda dependency, cold starts, eventual consistency).

Migration strategies by handler type:

HandlerStrategy
aws-certificatemanager/dns-validated-certificate-handlerReplace with aws.acm.Certificate, aws.route53.Record, and aws.acm.CertificateValidation
aws-ec2/restrict-default-security-group-handlerReplace with aws.ec2.DefaultSecurityGroup resource with empty ingress/egress rules
aws-ecr/auto-delete-images-handlerReplace aws-native:ecr:Repository with aws.ecr.Repository with forceDelete: true
aws-s3/auto-delete-objects-handlerReplace aws-native:s3:Bucket with aws.s3.Bucket with forceDestroy: true
aws-s3/notifications-resource-handlerReplace with aws.s3.BucketNotification
aws-logs/log-retention-handlerReplace with aws.cloudwatch.LogGroup with explicit retentionInDays
aws-iam/oidc-handlerReplace with aws.iam.OpenIdConnectProvider
aws-route53/delete-existing-record-set-handlerReplace with aws.route53.Record with allowOverwrite: true
aws-dynamodb/replica-handlerReplace with aws.dynamodb.TableReplica

Cross-account/region handlers:

  • aws-cloudfront/edge-function → Use aws.lambda.Function with region: "us-east-1"

  • aws-route53/cross-account-zone-delegation-handler → Use separate aws provider with cross-account role assumption

Graceful degradation for unknown handlers:

  1. Keep the CustomResourceEmulator (default behavior)

  2. Document the custom resource in the migration report with:

    • Original handler name and purpose (if discernible from CDK path)

    • Note that it uses Lambda invocation at runtime

    • Recommend user review for potential native replacement

2.2 Provider Strategy
  • Default: Use aws-native whenever the resource type is available.

  • Fallback: Use aws when aws-native does not support equivalent features.

2.3 Assets & Bundling

CDK uses Assets and Bundling to handle deployment artifacts. These are processed by the CDK CLI before CloudFormation deployment and appear in the cdk.out directory alongside *.assets.json metadata files. CloudFormation templates contain hard-coded references to asset locations (S3 bucket/key or ECR repo/tag).

# Inspect asset definitions
jq '.files, .dockerImages' cdk.out/*.assets.json

Migration strategies by asset type:

Asset TypeDetectionPulumi Migration
Docker ImagedockerImages in assets.jsonUse docker-build.Image to build and push. Replace hard-coded ECR URI with image output.
File with build commandfiles with executable fieldFlag to user - build command needs setup in Pulumi
Static filefiles without executable, no bundling in CDK sourceUse pulumi.FileArchive or pulumi.FileAsset
Bundled filefiles without executable, but CDK source uses bundlingFlag to user - bundling needs setup in Pulumi

Detecting Bundling in CDK Source:

Check the CDK source code for bundling constructs (NodejsFunction, PythonFunction, GoFunction, or resources using the bundling option). If bundling is used, the build step needs to be replicated in Pulumi for ongoing development - otherwise source changes would require manually re-running cdk synth.

When bundling is detected, inform the user:

Build Step Detected: This CDK application uses <BUNDLING_TYPE> which builds deployable artifacts during synthesis. This build step needs to be replicated in Pulumi for ongoing development.

Options:

  1. CI/CD Pipeline (Recommended): Move the build step to your CI pipeline and reference the pre-built artifact in Pulumi

  2. Pulumi Command Provider: Use command.local.Command to run the build command during pulumi up

  3. Pre-build Script: Create a build script that runs before pulumi up and outputs to a known location

Each option has tradeoffs around caching, reproducibility, and deployment speed. For production workloads, option 1 is typically preferred.

2.4 TypeScript Handling for aws-native

aws-native outputs often include undefined. Avoid ! non-null assertions. Always safely unwrap with .apply():

// ❌ WRONG - Will cause TypeScript errors
functionName: lambdaFunction.functionName!,

// ✅ CORRECT - Handle undefined safely
functionName: lambdaFunction.functionName.apply(name => name || ""),
2.5 Environment Logic Preservation

Carry forward all conditional behaviors:

if (currentEnv.createVpc) {
  // create resources
} else {
  const vpcId = pulumi.output(currentEnv.vpcId);
}
3. Resource Import (optional)

After conversion you can optionally import the existing resources to now be managed by Pulumi. If the user does not request this you should suggest this as a follow up step to conversion.

  • Always start with automated import using the cdk-importer tool. Follow cdk-importer.md to perform the automated import.

  • For any resources that fail to import with the automated tool, import them manually.

If you need to manually import resources:

3.1 Running preview after import

After performing an import you need to run pulumi preview to ensure there are no changes. No changes means:

  • NO updates

  • NO replaces

  • NO creates

  • NO deletes

If there are changes you must investigate and update the program until there are no changes.

Working with the User

If the user asks for help planning or performing a CDK to Pulumi migration use the information above to guide the user towards the automated migration approach.

For Detailed Documentation

When the user wants to deviate from the recommended path detailed above, use the web-fetch tool to get content from the official Pulumi documentation -> https://www.pulumi.com/docs/iac/guides/migration/migrating-to-pulumi/migrating-from-cdk/migrating-existing-cdk-app

This documentation covers topics:

  • Migration Strategy

    • Convert vs. Rewrite

    • Import vs. Rehydrate

    • Best Practices

  • Handling Multiple CDK Stacks

  • Handling CDK Stages

  • Code organization

  • Converting CDK Constructs

  • Execution Strategies

    • Automated Migration (recommended)

    • Manual Migration

OUTPUT FORMAT (REQUIRED)

When performing a migration, always produce:

  1. Overview (high-level description)

  2. Migration Plan Summary

  3. Pulumi Code Outputs (TypeScript; structured by file)

  4. Resource Mapping Table (CDK → Pulumi)

  5. Custom Resources Summary (if any):

    • Handlers migrated to native Pulumi resources

    • Handlers kept as CustomResourceEmulator with rationale

    • Any handlers requiring user attention

  6. Assets & Bundling Summary (if any):

    • Migrated: Assets successfully converted (e.g., Docker images → docker-build.Image, static files → pulumi.FileArchive)

    • Requires attention: Assets with bundling steps, options presented, and decision if made

  7. Final Migration Report (PR-ready)

  8. Next Steps (optional refactors)

Keep code syntactically valid and clearly separated by files.

Files

cdk-importer.md

Pulumi CDK Importer Tool

This tool assists migrating CDK-managed infrastructure to Pulumi. It imports existing AWS resources from CloudFormation stacks into Pulumi state.

Installation

pulumi plugin install tool cdk-importer

Credentials

Running the cdk-importer tool requires credentials loaded via Pulumi ESC.

  • If the user has already provided an ESC environment, use it.

  • If no ESC environment is specified, ask the user which ESC environment to use before proceeding with using the tool.

You MUST confirm the AWS region with the user. The results may be incorrect if ran with the wrong AWS Region. The region can be set with the AWS_REGION environment variable

Commands

program import

Import into the selected Pulumi stack using an existing generated Pulumi program.

pulumi plugin run cdk-importer -- program import \
  --program-dir ./generated \
  --stack MyStack

Required flags:

  • --program-dir: Path to an existing Pulumi program generated from a CDK app

  • --stack: CloudFormation stack name (can be specified multiple times or comma-separated)

Optional flags:

  • --import-file: Path to write a Pulumi bulk import file with failing resources (defaults to import.json when provided without a value)

  • --debug: Enable line by line logging of imported resources

Behavior:

  • Runs against the selected Pulumi stack.

  • With --import-file, writes the bulk import file after import. The file will only contain entries for resources that failed to import with <PLACEHOLDER> ids.

  • Can be run iteratively to progressively import resources.

Example Output:

[INFO] Getting stack resources component="cdk-importer" stack=NeoExample-Dev
[INFO] Starting up providers... component="cdk-importer"
[INFO] Importing stack... component="cdk-importer"
[INFO] Run complete component="cdk-importer" status="success" resourcesImported=50 resourcesFailedToImport=0 stack="NeoExample-Dev" importFile="/workspace/pulumi-example-app-neo/import.json" importFileExists=true

Import File Output

The generated import.json includes:

  • Full AWS resource metadata (type, logical name, provider reference, component bit, provider version)

  • Property subsets captured during provider interception

Resources with composite identifiers may show <PLACEHOLDER> IDs that need manual completion before running pulumi import --file import.json.

Unsupported Resources

Resources that cannot be imported:

  • CFN Custom Resources (aws-native:cloudformation:CustomResourceEmulator)

Example Workflow

  1. Generate a Pulumi program from your CDK app using cdk2pulumi

  2. Import into your real stack:

    pulumi plugin run cdk-importer -- program import \
      --program-dir ./pulumi-program-dir \
      --stack CdkStack

Handling Failures

This tool may not support 100% of the CloudFormation resources in the stack. For unsupported resources it is necessary to find the import ID and import manually.

Example output:

[INFO] Getting stack resources component="cdk-importer" stack=NeoExample-Dev
[INFO] Starting up providers... component="cdk-importer"
[INFO] Importing stack... component="cdk-importer"
[INFO] Pulumi errors component="cdk-importer" details=urn:pulumi:dev::cdk-convert-example::aws:rds/proxyDefaultTargetGroup:ProxyDefaultTargetGroup::DatabaseDbClusterDbProxyProxyTargetGroupA552DCC1: Don't have an ID!: aws:rds/proxyDefaultTargetGroup:ProxyDefaultTargetGroup neo-example-dev-database-db-cluster-db-proxy-eede4daa urn:pulumi:dev::cdk-convert-example::aws:rds/proxyDefaultTargetGroup:ProxyDefaultTargetGroup::DatabaseDbClusterDbProxyProxyTargetGroupA552DCC1

update failed
[INFO] Run complete component="cdk-importer" status="failed" resourcesImported=69 resourcesFailedToImport=1 stack="NeoExample-Dev"
- operation failed

Example Failure Workflow:

  1. Import ran with error

  2. Review failures and run pulumi preview.

    • Any resources that fail to import should appear as creations in the preview.

    • Optionally run program import with the --import-file flag to generate a import.json file with the failing resources.

  3. Manually import remaining resources

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs network access, Needs a command-line tool, Needs Node.js

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Pulumi
Publisher
Pulumi (Official)
Source
pulumi/agent-skills · migration/skills/pulumi-cdk-to-pulumi · commit 82f222a
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Pulumi.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download pulumi-cdk-to-pulumi.zip