feat(gen2-migration): add geo category code generation for gen2-migration #14596
Open
sai-ray wants to merge 16 commits intogen2-migrationfrom
Open
feat(gen2-migration): add geo category code generation for gen2-migration #14596sai-ray wants to merge 16 commits intogen2-migrationfrom
sai-ray wants to merge 16 commits intogen2-migrationfrom
Conversation
…discriminated union
…p level resource.ts
packages/amplify-cli/src/commands/gen2-migration/generate/backend/synthesizer.ts
Fixed
Show fixed
Hide fixed
packages/amplify-cli/src/commands/gen2-migration/generate/backend/synthesizer.ts
Fixed
Show fixed
Hide fixed
packages/amplify-cli/src/commands/gen2-migration/generate/backend/synthesizer.ts
Fixed
Show fixed
Hide fixed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds geo category (
Map,PlaceIndex,GeofenceCollection) codegen support to the gen2-migration pipeline. When a Gen1 app has geo resources, thegeneratestep now produces per-resource CDK L1 constructs viacdk-from-cfn, wraps each in its own independent CloudFormation stack, and wires them intobackend.tsthrough a top-leveldefineGeo(backend)aggregator.Description of changes
Geo Definition Fetcher (
app_geo_definition_fetcher.ts)AppGeoDefinitionFetcherReads thegeokey from the deployedamplify-meta.jsonin S3 and returns a record ofGeoResourceDefinitionentries keyed by resource name. Follows the same pattern asAppAnalyticsDefinitionFetcherbut uses explicitif/throwinstead ofassert.Per-Resource Generator (
geo-resource-renderer.ts)renderGeoResourcegenerates aresource.tsfor each geo resource that creates its own independent stack viabackend.createStack(), adds a dependency on the auth stack, and instantiates the construct with dynamic props (branchName,authRoleName,unauthRoleName,userPoolId, group roles frombackend.auth.resources) and static props (mapName,mapStyle,indexName, etc. from deployed parameters). Handles all three service types with a switch onserviceName.Top-Level Aggregator (
geo-renderer.ts)renderGeogenerates the top-levelamplify/geo/resource.tsthat imports all per-resourcedefine*functions, calls each one assigning the return value to a variable using the resource name, then callsbackend.addOutput()with geo configuration using construct output properties (.name,.region,.style) for maps, search indices, and geofence collections.Backend Synthesizer (
synthesizer.ts)geotoBackendRenderParameterswith animportFrompath. Whengeois present, therender()method addsimport { defineGeo }andconst geo = defineGeo(backend)afterdefineBackend(), following the analytics pattern.Migration Pipeline (
migration-pipeline.ts)geotoGen2RenderingOptions. When geo resources are present,createGen2Renderer()creates theamplify/geo/directory, iterates over each resource creating per-resource directories and renderers (callinggenerateGeoL1Code()thenrenderGeoResource()), collects all render params, then creates a renderer for the top-levelrenderGeo()aggregator.Command Handlers (
command-handlers.ts)geofrom theunsupportedCategoriesmap. AddedAppGeoDefinitionFetcherinstantiation inprepare()and wired it throughCodegenCommandParameterstogenerateGen2Code(), which fetches geo definitions and passes them toGen2RenderingOptions.cdk-from-cfn.tsType Interfaces : Added
GeoResourceDefinitionto model geo entries fromamplify-meta.json(service type, S3 template URL, logical ID). AddedGeoCodegenResultas a discriminated union ofMapCodegenResult,PlaceIndexCodegenResult, andGeofenceCollectionCodegenResult, each carrying typed service-specific fields (mapName/mapStyle,indexName/dataProvider/dataSourceIntendedUse,collectionName) plus common auth parameter metadata (userPoolIdParamName,groupRoles).postTransmuteFn::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.preTransmuteFn::JoinGroupRole Fix: Gen1 geo templates construct group role names viaFn::JoinofUserPoolIdand aGroupRolesuffix.cdk-from-cfntranslates this into.join('-')which produces a plain string, breaking CloudFormation's cross-stack dependency detection. The fix replaces theseFn::Joinpatterns with a directRefto the correspondingGroupRoleparameter, preserving CDK token chains for correct deployment ordering.Geo L1 Code Generation:
generateGeoL1CodeFetches the CFN template from S3, fetches deployed stack parameters, appliespreTransmute(envrename, condition resolution,GroupRolefix), callscdk_from_cfn.transmute(), appliespostTransmute(FindInMapfix), writes the construct file, extracts the class name, and categorizes deployed parameters into the typedGeoCodegenResult.Generated Output Structure
Dependencies -
cdk-from-cfnversion needs to be bumped to includeCustom::LambdaCalloutresource type support. Until that version is published, thetransmute()call will fail on geo CFN templates.Issue #, if available
Description of how you validated changes
Checklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.