Skip to content

feat(gen2-migration): add geo category code generation for gen2-migration #14596

Open
sai-ray wants to merge 16 commits intogen2-migrationfrom
sai/geo-codegen-for-gen2-migration
Open

feat(gen2-migration): add geo category code generation for gen2-migration #14596
sai-ray wants to merge 16 commits intogen2-migrationfrom
sai/geo-codegen-for-gen2-migration

Conversation

@sai-ray
Copy link
Contributor

@sai-ray sai-ray commented Feb 16, 2026

This PR adds geo category (Map, PlaceIndex, GeofenceCollection) codegen support to the gen2-migration pipeline. When a Gen1 app has geo resources, the generate step now produces per-resource CDK L1 constructs via cdk-from-cfn, wraps each in its own independent CloudFormation stack, and wires them into backend.ts through a top-level defineGeo(backend) aggregator.

Description of changes

  1. Geo Definition Fetcher (app_geo_definition_fetcher.ts)

  • AppGeoDefinitionFetcher Reads the geo key from the deployed amplify-meta.json in S3 and returns a record of GeoResourceDefinition entries keyed by resource name. Follows the same pattern as AppAnalyticsDefinitionFetcher but uses explicit if/throw instead of assert.
  1. Per-Resource Generator (geo-resource-renderer.ts)

  • renderGeoResource generates a resource.ts for each geo resource that creates its own independent stack via backend.createStack(), adds a dependency on the auth stack, and instantiates the construct with dynamic props (branchName, authRoleName, unauthRoleName, userPoolId, group roles from backend.auth.resources) and static props (mapName, mapStyle, indexName, etc. from deployed parameters). Handles all three service types with a switch on serviceName.
  1. Top-Level Aggregator (geo-renderer.ts)

  • renderGeo generates the top-level amplify/geo/resource.ts that imports all per-resource define* functions, calls each one assigning the return value to a variable using the resource name, then calls backend.addOutput() with geo configuration using construct output properties (.name, .region, .style) for maps, search indices, and geofence collections.
  1. Backend Synthesizer (synthesizer.ts)

  • Added geo to BackendRenderParameters with an importFrom path. When geo is present, the render() method adds import { defineGeo } and const geo = defineGeo(backend) after defineBackend(), following the analytics pattern.
  1. Migration Pipeline (migration-pipeline.ts)

  • Added geo to Gen2RenderingOptions. When geo resources are present, createGen2Renderer() creates the amplify/geo/ directory, iterates over each resource creating per-resource directories and renderers (calling generateGeoL1Code() then renderGeoResource()), collects all render params, then creates a renderer for the top-level renderGeo() aggregator.
  1. Command Handlers (command-handlers.ts)

  • Removed geo from the unsupportedCategories map. Added AppGeoDefinitionFetcher instantiation in prepare() and wired it through CodegenCommandParameters to generateGen2Code(), which fetches geo definitions and passes them to Gen2RenderingOptions.
  1. cdk-from-cfn.ts

  • Type Interfaces : Added GeoResourceDefinition to model geo entries from amplify-meta.json (service type, S3 template URL, logical ID). Added GeoCodegenResult as a discriminated union of MapCodegenResult, PlaceIndexCodegenResult, and GeofenceCollectionCodegenResult, each carrying typed service-specific fields (mapName/mapStyle, indexName/dataProvider/dataSourceIntendedUse, collectionName) plus common auth parameter metadata (userPoolIdParamName, groupRoles).

  • postTransmute Fn::FindInMapToken Crash Fix: Thecdk-from-cfnlibrary translates CFNFn::FindInMapinto plain JS dictionary lookups that crash at CDK synth time becausethis.regionis a CDK Token, not a concrete string.postTransmutereplacesRecord<string, Record<string, string>>declarations withcdk.CfnMappingconstructors and bracket lookups with.findInMap()calls, producing properFn::FindInMap` intrinsics in synthesized CloudFormation.

  • preTransmute Fn::Join GroupRole Fix: Gen1 geo templates construct group role names via Fn::Join of UserPoolId and a GroupRole suffix. cdk-from-cfn translates this into .join('-') which produces a plain string, breaking CloudFormation's cross-stack dependency detection. The fix replaces these Fn::Join patterns with a direct Ref to the corresponding GroupRole parameter, preserving CDK token chains for correct deployment ordering.

  • Geo L1 Code Generation: generateGeoL1Code Fetches the CFN template from S3, fetches deployed stack parameters, applies preTransmute (env rename, condition resolution, GroupRole fix), calls cdk_from_cfn.transmute(), applies postTransmute (FindInMap fix), writes the construct file, extracts the class name, and categorizes deployed parameters into the typed GeoCodegenResult.

Generated Output Structure

amplify/
  geo/
    resource.ts                        # defineGeo() aggregator + backend.addOutput()
    MyMap/
      MyMap-construct.ts               # L1 CDK code (cdk-from-cfn + postTransmute)
      resource.ts                      # defineMyMap() (independent stack)
    MySearch/
      MySearch-construct.ts
      resource.ts                      # defineMySearch() (independent stack)
    MyGeofence/
      MyGeofence-construct.ts
      resource.ts                      # defineMyGeofence() (independent stack)
  backend.ts                           # import { defineGeo } + defineGeo(backend)

Dependencies -

  • To fully support geo codegen migration, the cdk-from-cfn version needs to be bumped to include Custom::LambdaCallout resource type support. Until that version is published, the transmute() call will fail on geo CFN templates.

Issue #, if available

Description of how you validated changes

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.

@sai-ray sai-ray changed the title feat(gen2-migration): geo category code generation for gen2-migration [WIP] feat(gen2-migration): add geo category code generation for gen2-migration Feb 20, 2026
@sai-ray sai-ray marked this pull request as ready for review February 20, 2026 18:00
@sai-ray sai-ray requested a review from a team as a code owner February 20, 2026 18:00
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.

1 participant