Skip to content

feat(cli): support custom CDK resource migration in gen2-migration generate#14863

Open
sanjanaravikumar-az wants to merge 12 commits intodevfrom
sanjrkmr/dev-custom-resource
Open

feat(cli): support custom CDK resource migration in gen2-migration generate#14863
sanjanaravikumar-az wants to merge 12 commits intodevfrom
sanjrkmr/dev-custom-resource

Conversation

@sanjanaravikumar-az
Copy link
Copy Markdown
Contributor

@sanjanaravikumar-az sanjanaravikumar-az commented May 6, 2026

Description of changes

Adds support for migrating Gen1 custom CDK resources (amplify/backend/custom/*) to Gen2 during amplify gen2-migration generate.

What it does

When a Gen1 app has custom CDK resources (category custom, service customCDK), the migration tool now:

  1. Discovers them via custom:customCDK in KNOWN_RESOURCE_KEYS
  2. Assesses them as generate=supported, refactor=not-applicable
  3. Generates Gen2 code:
    • Copies the custom resource directory to amplify/custom/<name>/
    • Transforms cdk-stack.ts via AST rewriting (removes Gen1 helpers, rewrites dependency references, changes extends Stack to extends Construct, renames class)
    • Renames cdk-stack.tsconstruct.ts
    • Generates a resource.ts wrapper with defineXxx(backend) factory function
    • Merges non-excluded dependencies into root package.json
    • Contributes namespace import + defineXxx(backend) call to backend.ts
  4. Skips them in lock and refactor (stateless — no CloudFormation resources to protect or move)

Also includes the finance-tracker migration app which exercises two custom resources (customfinance for SNS topics, customresolver for a custom VTL resolver).

Key design decisions

  • Custom resources use a construct.ts + resource.ts wrapper pattern (unlike other categories that export directly). The wrapper returns the construct instance so post-generate scripts can access its properties.
  • The AmplifyHelperTransformer rewrites Gen1 patterns to Gen2 equivalents via TypeScript AST transformation — handles AmplifyHelpers.getProjectInfo(), addResourceDependency, CfnParameter('env'), CDK v1 imports, and dependency property access chains.
  • RootPackageJsonGenerator now uses maxVersion deduplication and strips CDK v1 / Gen1-only packages.

Issue #, if available

Description of how you validated changes

  • All 13 generate snapshot tests pass (including finance-tracker)
  • All 28 custom resource unit tests pass (transformer + generator)
  • All assess and lock tests pass (74 total across 5 suites)
  • Build compiles cleanly
  • E2E tested with npm run test:e2e on finance-tracker app

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

sanjanaravikumar-az and others added 5 commits May 4, 2026 17:34
…Backend type

Update the custom resource generator to:
- Return the construct instance from defineXxx() wrapper functions
- Use Backend type annotation instead of any for the backend parameter
- Rename cdk-stack.ts to construct.ts (not resource.ts)
- Use _prefixed variable name in post-generate to avoid shadowing
- Fix post-generate to look in construct.ts for table name pattern
- Update snapshots and tests to match
@sanjanaravikumar-az sanjanaravikumar-az requested a review from a team as a code owner May 6, 2026 15:33
@sanjanaravikumar-az sanjanaravikumar-az changed the title feat(cli-internal): support custom CDK resource migration in gen2-migration generate feat(cli): support custom CDK resource migration in gen2-migration generate May 6, 2026
@sanjanaravikumar-az sanjanaravikumar-az enabled auto-merge (squash) May 6, 2026 16:16
Comment thread reports/report.xml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants