Skip to content

fix: Lambda RMU on LocalStack with DynamoDB Streams#783

Merged
j5ik2o merged 10 commits into
mainfrom
fix/lambda-rmu-on-localstack
Mar 31, 2026
Merged

fix: Lambda RMU on LocalStack with DynamoDB Streams#783
j5ik2o merged 10 commits into
mainfrom
fix/lambda-rmu-on-localstack

Conversation

@j5ik2o
Copy link
Copy Markdown
Owner

@j5ik2o j5ik2o commented Mar 31, 2026

Summary

  • LocalStack上でLambdaベースのRead Model Updater(RMU)をDynamoDB Streams経由で動作させるための修正
  • Lambda ビルド/デプロイスクリプト、ハンドラーの追加
  • E2Eテストフローを Lambda デプロイ → DynamoDB Streams トリガー → リードモデル検証に更新

Changes

Lambda infrastructure

  • packages/bootstrap/src/lambda-rmu-handler.ts: Lambda handler entry point
  • tools/scripts/build-read-model-updater-lambda.sh: esbuild + Prisma native binaries をZIPにパッケージ
  • tools/scripts/build-read-model-updater-lambda.docker-inner.sh: linux/amd64 Docker内ビルド、不要なPrismaバイナリを除去
  • tools/scripts/deploy-read-model-updater-localstack.sh: Lambda作成/更新、ESM作成、Active/Enabled待機

LocalStack configuration

  • LAMBDA_EXECUTOR: docker, MAIN_CONTAINER_NAME, LAMBDA_DOCKER_NETWORK を追加(Docker Desktop上のLambdaコンテナネットワーク問題を解決)
  • lambda, iam をSERVICESに追加
  • AWS_REGION を dynamodb-setup に追加(リージョン不一致を修正)

RMU payload decoding fix

  • LocalStack の DynamoDB Stream イベントでは B フィールドに生JSON文字列が入る(Base64ではなく)
  • 3パターン対応: 生JSON(LocalStack)、Base64(AWS Lambda)、カンマ区切り数値(ローカルRMU)
  • Prisma binaryTargetsrhel-openssl-1.0.x を追加(Amazon Linux 2 Lambda runtime用)

Test plan

  • E2Eテスト(docker-compose-e2e-test.sh -l)がLocalStack Lambda経由で全項目パス
    • CreateGroupChat → AddMember → PostMessage → リードモデル反映確認
    • RenameGroupChat → リードモデル反映確認
    • GetGroupChat / GetGroupChats / GetMember / GetMembers / GetMessage / GetMessages
    • DeleteMessage → RemoveMember → DeleteGroupChat

Note

Medium Risk
Touches the read-model projection path and adds LocalStack Lambda build/deploy automation, which can affect event decoding/projection correctness and CI reliability, but is scoped to LocalStack/dev workflows.

Overview
Enable Lambda-based RMU on LocalStack. Adds a dedicated Lambda handler (lambda-rmu-handler.ts) plus new pnpm scripts and shell tooling to build a Linux/amd64 deployment zip (bundled with Prisma engines) and deploy it to LocalStack with IAM role + DynamoDB stream event-source mapping setup.

Make LocalStack + E2E flow deterministic. Updates Docker Compose LocalStack config to run lambda/iam with Docker executor/network settings, adjusts E2E compose to run the test container via a profile after Lambda deploy, and hardens verify-group-chat.sh with API/read-model polling to wait for stream→Lambda→MySQL projection.

Fix RMU stream payload decoding across environments. update-read-model.ts now handles three payload.B formats (raw JSON from LocalStack, base64 from AWS Lambda, and comma-separated bytes from local RMU), and Prisma binaryTargets are expanded for Lambda compatibility. CI installs AWS CLI v2, and common.env is introduced (gitignored) with defaults documented in BUILD/TEST docs.

Written by Cursor Bugbot for commit 8452498. This will update automatically on new commits. Configure here.

j5ik2o added 3 commits March 31, 2026 20:57
Add infrastructure for building and deploying the Read Model Updater
as a Lambda function on LocalStack with DynamoDB Streams trigger.
- Enable LAMBDA_EXECUTOR=docker, MAIN_CONTAINER_NAME, LAMBDA_DOCKER_NETWORK
  for correct Lambda container networking on Docker Desktop
- Add lambda and iam to LocalStack SERVICES
- Add AWS_REGION to dynamodb-setup to fix region mismatch
- Update E2E test script to build/deploy Lambda before running tests
- Update verify-group-chat.sh with polling for read model availability
….x target

- Support three DynamoDB B field formats: raw JSON (LocalStack),
  Base64 (AWS Lambda), and comma-separated numbers (local RMU)
- Add rhel-openssl-1.0.x to Prisma binaryTargets for Amazon Linux 2
- Strip unnecessary Prisma native binaries from Lambda ZIP
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 31, 2026

Image description CodeRabbit


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

j5ik2o added 4 commits March 31, 2026 21:02
…ipts

All package.json files pointed main at src/index.ts which breaks
esbuild bundling. Switch to dist/index.js with types field.
Add build-read-model-updater-lambda and deploy-read-model-updater-localstack
npm scripts to root package.json.
esbuild strips type-only imports so type-graphql cannot resolve
the input class at runtime. Use value imports and explicit type
function syntax @arg("input", () => Type) for all mutations.
… in compose-up

CI needs aws-cli for LocalStack Lambda deploy. common.env holds
local overrides and must not be committed. docker-compose-up.sh
now builds the Lambda zip and deploys to LocalStack automatically.
Update READMEs to check off "Read Model Updater on AWS Lambda".
Add LocalStack Lambda build/deploy instructions to BUILD_AND_TEST
docs in both Japanese and English.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between ca6f91d and b539b76 commits.
Files selected (29)
  • .github/workflows/ci.yml (1)
  • .gitignore (1)
  • .gitmodules (1)
  • README.ja.md (1)
  • README.md (1)
  • docs/BUILD_AND_TEST.ja.md (1)
  • docs/BUILD_AND_TEST.md (1)
  • mise.toml (1)
  • package.json (1)
  • packages/bootstrap/package.json (1)
  • packages/bootstrap/src/lambda-rmu-handler.ts (1)
  • packages/command/domain/package.json (1)
  • packages/command/interface-adaptor-if/package.json (1)
  • packages/command/interface-adaptor-impl/package.json (1)
  • packages/command/interface-adaptor-impl/src/graphql/resolvers.ts (8)
  • packages/command/processor/package.json (1)
  • packages/infrastructure/package.json (1)
  • packages/query/interface-adaptor/package.json (1)
  • packages/rmu/package.json (1)
  • packages/rmu/prisma/schema.prisma (1)
  • packages/rmu/src/update-read-model.ts (1)
  • tools/docker-compose/docker-compose-databases.yml (2)
  • tools/docker-compose/docker-compose-e2e-test.yml (1)
  • tools/e2e-test/verify-group-chat.sh (14)
  • tools/scripts/build-read-model-updater-lambda.docker-inner.sh (1)
  • tools/scripts/build-read-model-updater-lambda.sh (1)
  • tools/scripts/deploy-read-model-updater-localstack.sh (1)
  • tools/scripts/docker-compose-e2e-test.sh (2)
  • tools/scripts/docker-compose-up.sh (2)
Files not summarized due to errors (29)
  • .github/workflows/ci.yml (nothing obtained from openai)
  • .gitignore (nothing obtained from openai)
  • README.md (nothing obtained from openai)
  • README.ja.md (nothing obtained from openai)
  • .gitmodules (nothing obtained from openai)
  • docs/BUILD_AND_TEST.ja.md (nothing obtained from openai)
  • packages/bootstrap/package.json (nothing obtained from openai)
  • packages/command/domain/package.json (nothing obtained from openai)
  • docs/BUILD_AND_TEST.md (nothing obtained from openai)
  • mise.toml (nothing obtained from openai)
  • packages/bootstrap/src/lambda-rmu-handler.ts (nothing obtained from openai)
  • package.json (nothing obtained from openai)
  • packages/command/interface-adaptor-impl/package.json (nothing obtained from openai)
  • packages/infrastructure/package.json (nothing obtained from openai)
  • packages/query/interface-adaptor/package.json (nothing obtained from openai)
  • packages/command/processor/package.json (nothing obtained from openai)
  • packages/command/interface-adaptor-impl/src/graphql/resolvers.ts (nothing obtained from openai)
  • packages/command/interface-adaptor-if/package.json (nothing obtained from openai)
  • packages/rmu/package.json (nothing obtained from openai)
  • tools/docker-compose/docker-compose-databases.yml (nothing obtained from openai)
  • packages/rmu/src/update-read-model.ts (nothing obtained from openai)
  • tools/docker-compose/docker-compose-e2e-test.yml (nothing obtained from openai)
  • tools/e2e-test/verify-group-chat.sh (nothing obtained from openai)
  • packages/rmu/prisma/schema.prisma (nothing obtained from openai)
  • tools/scripts/build-read-model-updater-lambda.docker-inner.sh (nothing obtained from openai)
  • tools/scripts/build-read-model-updater-lambda.sh (nothing obtained from openai)
  • tools/scripts/deploy-read-model-updater-localstack.sh (nothing obtained from openai)
  • tools/scripts/docker-compose-e2e-test.sh (nothing obtained from openai)
  • tools/scripts/docker-compose-up.sh (nothing obtained from openai)
Files not reviewed due to errors (29)
  • docs/BUILD_AND_TEST.ja.md (no response)
  • .github/workflows/ci.yml (no response)
  • README.ja.md (no response)
  • .gitignore (no response)
  • .gitmodules (no response)
  • README.md (no response)
  • package.json (no response)
  • docs/BUILD_AND_TEST.md (no response)
  • packages/bootstrap/src/lambda-rmu-handler.ts (no response)
  • packages/command/domain/package.json (no response)
  • mise.toml (no response)
  • packages/bootstrap/package.json (no response)
  • packages/command/interface-adaptor-impl/package.json (no response)
  • packages/command/interface-adaptor-if/package.json (no response)
  • packages/command/processor/package.json (no response)
  • packages/infrastructure/package.json (no response)
  • packages/command/interface-adaptor-impl/src/graphql/resolvers.ts (no response)
  • packages/query/interface-adaptor/package.json (no response)
  • packages/rmu/prisma/schema.prisma (no response)
  • tools/docker-compose/docker-compose-databases.yml (no response)
  • packages/rmu/src/update-read-model.ts (no response)
  • packages/rmu/package.json (no response)
  • tools/docker-compose/docker-compose-e2e-test.yml (no response)
  • tools/e2e-test/verify-group-chat.sh (no response)
  • tools/scripts/build-read-model-updater-lambda.docker-inner.sh (no response)
  • tools/scripts/build-read-model-updater-lambda.sh (no response)
  • tools/scripts/docker-compose-e2e-test.sh (no response)
  • tools/scripts/deploy-read-model-updater-localstack.sh (no response)
  • tools/scripts/docker-compose-up.sh (no response)
Review comments generated (0)
  • Review: 0
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment thread tools/scripts/build-read-model-updater-lambda.docker-inner.sh
j5ik2o added 2 commits March 31, 2026 21:27
…tion

The inner build script was running pnpm install directly on the
bind-mounted host workspace, overwriting macOS/Windows node_modules
with Linux-specific Prisma binaries. Now rsync sources to /build
inside the container and only copy the final zip back to the host.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between b539b76 and 0174481 commits.
Files selected (1)
  • tools/scripts/build-read-model-updater-lambda.docker-inner.sh (1)
Files not summarized due to errors (1)
  • tools/scripts/build-read-model-updater-lambda.docker-inner.sh (nothing obtained from openai)
Files not reviewed due to errors (1)
  • tools/scripts/build-read-model-updater-lambda.docker-inner.sh (no response)
Review comments generated (0)
  • Review: 0
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment thread docs/BUILD_AND_TEST.md
The file was referenced by documentation and shell scripts but never
committed, so the auto-copy fallback in docker-compose-up.sh and
docker-compose-e2e-test.sh could never trigger.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 0174481 and 8452498 commits.
Files selected (1)
  • common.env.default (1)
Files not summarized due to errors (1)
  • common.env.default (nothing obtained from openai)
Files not reviewed due to errors (1)
  • common.env.default (no response)
Review comments generated (0)
  • Review: 0
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread .gitmodules
@@ -0,0 +1,3 @@
[submodule "references/okite-ai"]
path = references/okite-ai
url = git@github.com:j5ik2o/okite-ai.git
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated private git submodule accidentally committed

Medium Severity

A .gitmodules file referencing references/okite-ai via a private SSH URL (git@github.com:j5ik2o/okite-ai.git) is included in this PR but is entirely unrelated to the Lambda RMU / DynamoDB Streams changes. This will cause git clone --recursive (or git submodule update --init) to fail for anyone without SSH access to that private repository, breaking CI or onboarding flows.

Fix in Cursor Fix in Web

"STREAM_MAX_ITEM_COUNT": "${STREAM_MAX_ITEM_COUNT}",
}
}))
PY
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shell variable injection in Python heredoc breaks special characters

Low Severity

The <<PY heredoc performs shell variable expansion before passing content to python3. If any variable (e.g., DATABASE_URL_LAMBDA) contains double quotes, backslashes, or newlines, the generated Python string literals break, causing a syntax error and failing the deploy. Using a quoted heredoc (<<'PY') and passing values via environment variables or arguments to Python would be safer.

Fix in Cursor Fix in Web

@j5ik2o j5ik2o merged commit 86b4c1e into main Mar 31, 2026
8 checks passed
@j5ik2o j5ik2o deleted the fix/lambda-rmu-on-localstack branch March 31, 2026 13:53
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