refactor(infra/smalruby-api): rename Lambdas + import existing domain for prod cutover#575
Merged
Merged
Conversation
… for prod cutover prod カットオーバー (api.smalruby.app を旧 SAM スタックから CDK へ) に対応する 変更。ダウンタイムを最小化するため、既存の API Gateway カスタムドメインを 新規作成せずに import する。 Lambda 関数名変更: - smalruby-cors-proxy → smalruby-api-cors-proxy - smalruby-mesh-zone-get → smalruby-api-mesh-zone - smalruby-scratch-api-projects → smalruby-api-scratch-projects - smalruby-scratch-api-translate → smalruby-api-scratch-translate 旧 SAM スタックが使っていた `smalruby-cors-proxy` 等と衝突していたため、 すべて `smalruby-api-` プレフィックスで統一。stg は既存の関数を CFN が delete + create で置き換える (stg のみ短時間ダウンする)。 カスタムドメイン import: - `IMPORT_EXISTING_CUSTOM_DOMAIN=true` のとき、apigatewayv2.DomainName. fromDomainNameAttributes() で既存ドメインを参照 - ACM 証明書、Route53 レコードは作成せず再利用 - prod 用の .env.prod でこのフラグと既存の regional domain attributes を設定 Integration test の Origin を localhost:8601 → smalruby.app に変更: - prod CORS は localhost を許可しない (.env.prod で意図的に除外) - smalruby.app は両環境で常に許可されるため、両方で pass する prod 検証 (2026-04-29): - 全 4 endpoint 200/404/CORS 正常動作 - mesh-domain は旧 SAM secret_key 引き継ぎでドメイン継続性 OK - integration test 18 件すべて pass - ダウンタイム実測: 約 5 分 (CDK deploy + HTTP API mapping 反映) 旧 SAM スタック smalruby-infra-prod は CloudFormation から削除済み。 smalruby/smalruby-infra リポジトリの該当ディレクトリ deprecate は後続作業。 Refs: #573
prod カットオーバー (2026-04-29) で得た学びを今後のために記録: .claude/rules/infra/smalruby-api.md: - Lambda 関数名衝突 → smalruby-api- プレフィックスで回避 - カスタムドメイン import (fromDomainNameAttributes) でダウンタイム削減 - base path mapping は domain と切り離されている - integration test Origin は両環境で許可される値を使う - mesh-zone-get の secret key は引き継ぎ必須 (互換性破壊リスク) - import 時は manageRoute53Record で ARecord 作成をスキップ - CFN Delete 後は polling で消滅確認 - 検証は curl + Playwright で end-to-end .claude/rules/infra/development.md: - 汎用「旧スタック → CDK 移行チェックリスト」を追加 - 関数名衝突回避、import パターン、secret 引き継ぎ、カットオーバー手順
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.
Summary
prod カットオーバー (旧 SAM スタック
smalruby-infra-prod→ CDK スタックSmalrubyApiStack) に対応するためのコード変更。カットオーバー自体は本 PR を出す前にすでに実施済み (2026-04-29)。本 PR は実施したコード変更を develop に反映する。カットオーバーで変更した点
1. Lambda 関数名の
smalruby-api-プレフィックス統一旧 SAM スタックの Lambda 関数名と衝突していたため、CDK 側はすべて
smalruby-api-プレフィックスで統一:smalruby-cors-proxysmalruby-api-cors-proxysmalruby-mesh-zone-getsmalruby-api-mesh-zonesmalruby-scratch-api-projectssmalruby-api-scratch-projectssmalruby-scratch-api-translatesmalruby-api-scratch-translatestg では
-stgサフィックス、prod ではサフィックスなし。2. カスタムドメインの import 機能
ダウンタイム最小化のため、CDK スタックが既存の API Gateway カスタムドメイン (
api.smalruby.app) を 作成せずに参照 できる仕組みを追加。apigatewayv2.DomainName.fromDomainNameAttributes()を使用。.env.prodに以下を設定 (gitignored、.env.exampleに記載):これで:
b813732a-...) を再利用 (再発行不要)3. integration test の Origin 修正
CORS preflight test の Origin を
http://localhost:8601→https://smalruby.appに変更。prod では.env.prodで意図的に localhost を CORS 許可リストから除外しているため。smalruby.appは両環境で常に許可。カットオーバー実施記録 (2026-04-29 完了)
.env.prod作成 (MESH_ZONE_SECRET_KEYを旧 SAM 値で設定 → mesh ドメイン継続性 OK)aws apigateway delete-base-path-mapping)cdk deploy --context stage=prodで新スタックをapi.smalruby.appに紐付けaws cloudformation delete-stack --stack-name smalruby-infra-prod)ダウンタイム実測: 約 5 分
副次的な変更
.claude/rules/infra/smalruby-api.mdを更新 (新しい Lambda 名、import 機能、カットオーバー記録を反映).env.exampleにIMPORT_EXISTING_CUSTOM_DOMAINの説明を追加Verification
api.smalruby.app(18 件)projects/9999999999→ 404 (Issue bug: Scratchから読み込むが特定 URL で失敗する報告 (要追加情報) #573 の本丸バグが prod で完全解消)後続作業 (本 PR スコープ外)
smalruby/smalruby-infraリポジトリの該当ディレクトリ (lambda/cors-for-smalruby/,lambda/smalruby-cors-proxy/,lambda/smalruby-mesh-zone-get/,lambda/smalruby-scratch-api-proxy-*/) を deprecateTest plan
infra/smalruby-apiの unit tests / cdk synth / npm audit が greenscratch-gui/scratch-vmテストが greenRelated
Refs #573