feat(gen2-migration): support storage DynamoDB trigger for gen2-migration#14766
Open
sai-ray wants to merge 12 commits intogen2-migrationfrom
Open
feat(gen2-migration): support storage DynamoDB trigger for gen2-migration#14766sai-ray wants to merge 12 commits intogen2-migrationfrom
sai-ray wants to merge 12 commits intogen2-migrationfrom
Conversation
sai-ray
commented
Apr 9, 2026
| return await fetchActivityStats(); | ||
| } | ||
|
|
||
| const { userId } = event.arguments || {}; |
sai-ray
commented
Apr 9, 2026
sai-ray
commented
Apr 9, 2026
Add activityTrigger function to the discussions test app. The trigger fires on activity table stream inserts and increments a global counter at STATS#global. Updated fetchuseractivity to serve the counter via a new getActivityStats GraphQL query. Frontend shows the count on the activity page. Changes: - backend/activityTrigger.cjs: new trigger function source - backend/activityTrigger.package.json: trigger dependencies - backend/schema.graphql: added getActivityStats query type - backend/fetchuseractivity.cjs: added getStats routing - backend/configure.sh: copies trigger files on configure - src/main.js: loadActivityCounter on activity page - index.html: activityCounter element in activity page - src/graphql/queries.js: regenerated with getActivityStats - README.md: added trigger setup and update function steps --- Prompt: Add a DynamoDB storage Lambda trigger to the discussions test app with an activity counter that surfaces on the frontend, update golden backend files, configure scripts, and README.
…gger Add test that verifies the activityTrigger Lambda increments the global counter after a topic is created. Polls getActivityStats until activityCount > 0. --- Prompt: Sync updated discussions test app files from working copy to amplify-migration-apps.
Update pre-generate and post-generate snapshots to include the activityTrigger79c26ead function and its EventSourceMapping wiring on the activity table. Post-generate backend.ts includes the expected addEventSource/grantStreamRead/grantTableListStreams calls. Updated post-generate.ts to convert the trigger function to ESM. --- Prompt: Update snapshots with storage DynamoDB trigger after validating the Gen2 deployment works end-to-end.
Add codegen support for storage DynamoDB Lambda triggers in gen2-migration generate. When a storage table has triggerFunctions in cli-inputs.json, the generated backend.ts now includes addEventSource, grantStreamRead, and grantTableListStreams wiring. DynamoDBGenerator exposes resourceName, tableVariableName, and triggerFunctions getters. FunctionGenerator checks if it appears in any DynamoDBGenerator's triggerFunctions list and emits the wiring AST. generate.ts collects DynamoDBGenerator instances and wires them to FunctionGenerator. Updated discussions test app with activityTrigger79c26ead on the activity table. Captured all four snapshots (pre-generate, post-generate, pre-refactor, post-refactor) and verified the full migration workflow end-to-end. --- Prompt: Implement storage DynamoDB Lambda trigger codegen for the Gen1-to-Gen2 migration tool, following the existing model trigger pattern.
Add codegen support for storage DynamoDB Lambda triggers in gen2-migration generate. When a storage table has triggerFunctions in cli-inputs.json, the generated backend.ts now includes addEventSource, grantStreamRead, and grantTableListStreams wiring. DynamoDBGenerator exposes resourceName, tableVariableName, and triggerFunctions getters. FunctionGenerator checks if it appears in any DynamoDBGenerator's triggerFunctions list and emits the wiring AST. generate.ts collects DynamoDBGenerator instances and wires them to FunctionGenerator. Updated discussions test app with activityTrigger79c26ead on the activity table. Captured all four snapshots (pre-generate, post-generate, pre-refactor, post-refactor) and verified the full migration workflow end-to-end. --- Prompt: Implement storage DynamoDB Lambda trigger codegen for the Gen1-to-Gen2 migration tool, following the existing model trigger pattern.
Fix package.json name in pre-generate and post-generate snapshots to use -snapshot suffix (matching convention used by all other apps). Update post-generate snapshot via --updateSnapshot to match actual codegen output. All 12 generate snapshot tests pass. --- Prompt: Fix snapshot test failures for discussions app.
Replace real AWS account ID with placeholder in pre-refactor snapshots. Update post-refactor snapshot. All generate and refactor snapshot tests pass. --- Prompt: Fix refactor snapshot test failures caused by unsanitized account IDs.
Restore standard boilerplate in pre-generate and post-generate .gitignore files. Remove test-only deps from pre-generate package.json so codegen output matches expected snapshot. All 25 generate + refactor tests pass. --- Prompt: Fix CI lockfile failure and gitignore differences in discussion snapshots.
Run yarn install to add discussions snapshot dependencies to the lockfile. Fixes CI immutable lockfile check. --- Prompt: Fix CI lockfile failure by running yarn install.
Fix regex to match per-table stack names (storageActivityStack, storageBookmarksStack) instead of the old shared storageStack. Add bookmarks table name and S3 bucket name uncommenting. --- Prompt: Fix post-refactor.ts to match the actual codegen output and handle all post-refactor edits.
Replace real Amplify App ID (d1c9f6du1r9hog) with sanitized name (discussions) in all pre-refactor and post-refactor snapshot file contents and filenames. --- Prompt: Sanitize the app ID in refactor snapshot files.
22e396e to
abe54ff
Compare
Replace cli-inputs.json detection with CloudFormation template parsing, consistent with how model triggers are detected. FunctionGenerator now parses its own CFN template for EventSourceMapping resources with Ref: storageXStreamArn. Removed cross-generator wiring: DynamoDBGenerator getters, addDynamoDBGenerator(), and generate.ts wiring loop. Only function.generator.ts has codegen changes; dynamodb.generator.ts and generate.ts are reverted to their original state. All 25 snapshot tests pass. --- Prompt: Switch storage DynamoDB trigger detection from cli-inputs.json to CFN template parsing for consistency with model triggers.
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.
Description of changes
Adds codegen support for storage DynamoDB Lambda triggers in
gen2-migration generate. When a Gen1 function's CloudFormation template contains anEventSourceMappingwithRef: storage<tableName>StreamArn, the generatedbackend.tsnow includesaddEventSource,grantStreamRead, andgrantTableListStreamswiring between the table and the trigger function.This addresses the 🔴
Do you want to add a Lambda Trigger for your Tablefeature in the migration guide (under Storage → DynamoDB).Approach:
FunctionGeneratorparses its own CloudFormation template forEventSourceMappingresources that reference storage table streams viaRef: storage<tableName>StreamArn. This is consistent with how model triggers are detected (detectDynamoTriggerModelsparses forFn::ImportValue/Fn::Subpatterns). No cross-generator wiring needed — detection and generation happen entirely withinFunctionGenerator.Files changed:
function.generator.ts—detectStorageDynamoTriggers()andcontributeStorageDynamoTrigger()post-refactor.ts— fixed regex to match per-table stack names, added bookmarks and S3 bucket fixupsTest app:
Added
activityTrigger79c26eadto the discussions app — a Lambda triggered by theactivitytable stream that increments a global counter. Updated all four snapshot directories.Issue #, if available
Description of how you validated changes
npm run test:gen1— creates a topic, verifies the counter increments via the full trigger chain (model stream → recorduseractivity → activity table → activityTrigger → counter).Checklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.