2026/10/27 火

Daily AWS Blocks

Hosting の入口を CloudFront 以外から選べるように、API ごとに別の compute も割り当て可能に

リリースは無かったが、目立つ機能が2つ merge された。Hosting に frontDoor が加わり、アプリの入口を CloudFront・ALB・API Gateway・その組み合わせ・自作から選べるようになった。ApiNamespace は namespace ごとに専用の compute で動かせる。@aws-blocks/bb-data のデータベースエラーが 500 から 4xx に変わる挙動上の破壊的変更も入っており、次のリリースで効いてくる。

対象: 10/26 04:52 〜 10/27 07:02 JST

入口(front door)を選べる Hosting

アプリの公開アドレスを受け持ち、静的ファイル・サーバーレンダリング・画像最適化・バックエンド API に振り分ける部分を「front door」と呼ぶ。@aws-blocks/core の Hosting と @aws-blocks/hosting の HostingConstruct に省略可能な frontDoor が加わり、これを選べるようになった(#510)。選択肢は CloudFront(既定)、ALB、API Gateway、CloudFront を ALB の前に重ねた stacked、S3 の website bucket だけで出す 'none' の5つ。stacked では静的なルートを CloudFront のエッジが S3 から直接返し、ALB はそのエッジからの通信だけを受け付ける。

door の種類ごとに、その door が実際に扱える設定だけを features で渡す。扱えない設定を書くと TypeScript の型エラーになり、JavaScript でも synth 時に名前付きのエラーで止まる。kind: 'custom' を選べば自作の door も使える。door は @aws-blocks/hosting/constructs の defineFrontDoor で定義する関数1つで、synth 時に AWS Blocks が作った bucket・compute・API を受け取って公開 URL を返す。

new Hosting(stack, 'Hosting', {
  root: '..',
  api: stack,
  frontDoor: { kind: 'custom', door: myDoor, features: { waf: { enabled: true, webAclArn } } },
});

frontDoor を書かなければ、これまでどおり CloudFront の構成が生成される。変わるのはルーター用 CloudFront Function の中身だけで、同一サイトへのリダイレクトの防御と、ヘッダー規則のパス照合が直された。続く #1023 では、自前の 404 ページを持たない静的サイトにも、CloudFront 以外の door で既定の 404 ページが出るようになった。stacked と自作 door のエラーページが存在しないファイル名を指していた不具合も直っている。

非推奨・API の変更(Hosting)

これまでトップレベルにあった設定は、引き続き動くが @deprecated になった。移行先は frontDoor.features.<名前> で、該当するのは次のとおり。

// これまで
new Hosting(stack, 'Hosting', { root: '..', api: stack, waf: { enabled: true } });
// これから
new Hosting(stack, 'Hosting', { root: '..', api: stack, frontDoor: { kind: 'cloudfront', features: { waf: { enabled: true } } } });

Hosting.distribution と HostingConstruct.distribution は、CloudFront の distribution を持たない door(ALB・API Gateway など)を選んだ場合に FrontDoorNotCloudFrontError を投げるようになった。door の種類で処理を分けるときは、新しい HostingConstruct.frontDoorKind を見る。既定の CloudFront のまま使っている場合は影響しない。

破壊的変更(挙動): データベースエラーの 4xx 化

@aws-blocks/bb-data の Database は、一意制約違反と直列化の衝突を除く Postgres のエラーを、すべて 500 の QueryFailed として返していた。リクエスト自体に原因があるエラーは、名前付きの 4xx に分かれた(#1028)。

原因 新しい名前 status
RLS の WITH CHECK 拒否・権限不足 PermissionDenied 403
check 制約違反 CheckViolation 400
not-null 制約違反 NotNullViolation 400
外部キー違反 ForeignKeyViolation 409

影響を受けるのは、これらの失敗を isBlocksError(e, DatabaseErrors.QueryFailed) で拾っているコードと、status >= 500 をサーバー障害として扱っているコード。新しい名前で分岐し直す必要がある。どれも再試行されないエラーとして扱われ、テーブル名や列名を含むドライバーのメッセージは cause としてサーバー側に残る。例外が1つあり、withRLS() が SET LOCAL ROLE に失敗した場合は設定ミスとして 500 の QueryFailed のまま返り、直すための GRANT <role> TO CURRENT_USER がログに出る。changeset は @aws-blocks/bb-data と @aws-blocks/blocks の minor(どちらも 0.x)。

API namespace ごとの compute

ApiNamespace が4番目の引数 { compute } を受け取るようになり、重い処理の namespace だけを大きなメモリの compute で動かせる(#948)。

const reportsCompute = new Compute(scope, 'reports', { type: 'serverless', memory: 4096 });
export const reports = new ApiNamespace(scope, 'reports', (context) => ({ /* methods */ }), { compute: reportsCompute });

今は serverless の compute だけを受け付け、container を渡すと型エラーになる。別の BlocksBackend に属する compute を渡した場合は、synth 時に警告(blocks:apigateway:namespace-compute-not-owned)が出て、その namespace は既定の compute で動く。

その他(次のリリースに入る見込み)

AWS 上のフルスタックアプリを部品(Block)の組み合わせで作る OSS「AWS Blocks」の、GitHub 上の開発の動きをまとめた日報。文中の #番号 は GitHub 上の変更(PR)や議論(Issue)へのリンク。

10/27 のニュースへ