Skip to content

feat(gen2-migration): kinesis triggers codegen for gen2-migration#14787

Merged
iliapolo merged 5 commits intogen2-migrationfrom
sai/kinesis-triggers-codegen-for-gen2migration
Apr 16, 2026
Merged

feat(gen2-migration): kinesis triggers codegen for gen2-migration#14787
iliapolo merged 5 commits intogen2-migrationfrom
sai/kinesis-triggers-codegen-for-gen2migration

Conversation

@sai-ray
Copy link
Copy Markdown
Contributor

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

Description of changes

This PR adds codegen support for migrating Gen1 Kinesis Stream Lambda triggers in gen2-migration generate. When a Gen1 function's CloudFormation template contains an AWS::Lambda::EventSourceMapping referencing a Kinesis stream ARN, the generated Gen2 backend.ts wires the function as a Kinesis trigger using CDK's KinesisEventSource.

Codegen

The function generator gains two new methods:

  • detectKinesisTrigger() scans the CFN template for an EventSourceMapping with Ref: analytics<name>kinesisStreamArn and returns whether the function is a Kinesis trigger.
  • contributeKinesisTrigger() emits Stream.fromStreamArn() + KinesisEventSource + addEventSource() into backend.ts. We use Stream.fromStreamArn() because the analytics construct only exposes the ARN (L1 CfnStream), not an L2 Stream.

The existing contributeKinesisGrants() (IAM policy grants) is kept separate — it handles functions that call Kinesis APIs via SDK. The event source approach automatically grants the necessary read permissions through CDK, so there's no duplication.

Mood-board E2E app

  • Added KinesisEventCount model to the GraphQL schema and moodboardKinesisTrigger function that processes Kinesis stream records and writes event counts to AppSync.
  • Added KinesisTriggerLogs.tsx UI component and kinesis-trigger.test.ts E2E test.
  • Updated configure.sh, post-generate.ts, App.tsx, and README.md.
  • All 4 snapshots updated from a passing E2E run.

Issue #, if available

Fixes #14601
Follows the pattern established by the DynamoDB trigger PR (#14766).

Description of how you validated changes

  • Full E2E run (npm run test:e2e) without UPDATE_SNAPSHOTS — all 22 Gen1 tests passed, all 22 Gen2 tests passed, snapshots matched.
  • Refactor phase completed successfully for all resources including analytics/moodboardKinesis.
  • yarn test in packages/amplify-cli/ — generate and refactor snapshot tests pass for mood-board.
  • Pre-push hooks passed (sanitize, prettier, lint, commitlint, build-tests 22/22).

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 added 3 commits April 15, 2026 21:05
…tion generate

When a Gen1 function's CFN template contains an
AWS::Lambda::EventSourceMapping referencing a Kinesis stream
ARN, the generated Gen2 backend.ts now wires the function as
a Kinesis trigger using KinesisEventSource with
Stream.fromStreamArn().

Codegen changes in function.generator.ts:
- detectKinesisTrigger() scans CFN for EventSourceMapping
  with Ref: analytics<name>kinesisStreamArn
- contributeKinesisTrigger() emits Stream.fromStreamArn(),
  KinesisEventSource, and addEventSource() in backend.ts
- Both Kinesis IAM grants and event source permissions are
  kept (no permission scope reduction)

Mood-board E2E app changes:
- Added KinesisEventCount model to GraphQL schema
- Created moodboard2604151154c448f847 Kinesis trigger function
- Updated configure.sh, post-generate.ts, App.tsx, README.md
- Added KinesisTriggerLogs.tsx UI component
- Added kinesis-trigger.test.ts E2E test
- All 4 snapshots updated from passing E2E run
  (22 Gen1 + 22 Gen2 tests green)

Tested by running the full E2E system with UPDATE_SNAPSHOTS=1.
All 44 tests pass (22 Gen1, 22 Gen2) including the new kinesis
trigger test on both sides.
---
Prompt: Implement Kinesis Stream Trigger Migration for
gen2-migration generate. Add codegen support for migrating
Gen1 Kinesis Stream Lambda triggers. When a Gen1 function's
CFN template contains an EventSourceMapping referencing a
Kinesis stream ARN, generate KinesisEventSource wiring in
the Gen2 backend.ts.
…inesisTrigger

Rename the auto-generated function name
moodboard2604151154c448f847 to the human-readable
moodboardKinesisTrigger across all mood-board E2E app
snapshots, migration scripts, and source files.

E2E verified: 22/22 Gen1 tests passed, 22/22 Gen2 tests
passed, snapshots match.
---
Prompt: rename moodboard2604151154c448f847 to
moodboardKinesisTrigger for readability in the mood-board
E2E app
Fix generate snapshot: add amplify_outputs* to .gitignore,
fix KinesisEventCount table mapping formatting in
data/resource.ts.

Fix refactor snapshot: update storage S3 auto-delete custom
resource ARNs to match unit test mock physical ID format
(stackName/logicalId fallback for resources without CFN
outputs).
---
Prompt: fix snapshot test failures for mood-board generate
and refactor tests
@sai-ray sai-ray requested a review from a team as a code owner April 16, 2026 15:35
Comment thread amplify-migration-apps/mood-board/backend/kinesisTrigger.js Fixed
Comment thread amplify-migration-apps/mood-board/backend/kinesisTrigger.js Fixed
Rename `record` to `_record` in the Kinesis trigger handler
loop to satisfy unused-variable lint rules. The loop body
uses the iteration count, not the record contents.
---
Prompt: fix unused variable lint warning in kinesis trigger
handler
Comment thread amplify-migration-apps/mood-board/backend/configure.sh Outdated
The moodboardKinesisTrigger function directory always exists
in the snapshot, so the conditional check is not needed.
---
Prompt: remove unnecessary fallback guard in configure.sh
for kinesis trigger copy
Comment thread amplify-migration-apps/mood-board/backend/configure.sh Outdated
@iliapolo iliapolo enabled auto-merge (squash) April 16, 2026 19:58
@iliapolo iliapolo merged commit 1905a81 into gen2-migration Apr 16, 2026
4 checks passed
@iliapolo iliapolo deleted the sai/kinesis-triggers-codegen-for-gen2migration branch April 16, 2026 19:58
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