Skip to content

Commit 6355f6f

Browse files
fix(mesh-v2): appsync ログに retention を設定し既定を error レベルに絞る
prod の AppSync ログ群が無期限保持で ~7.8GB まで蓄積し CloudWatch 無料枠 を超過していた。 - logConfig.retention = ONE_MONTH を設定(AppSync 管理のロググループに Custom::LogRetention で保持期間を付与。無期限蓄積を止める) - fieldLogLevel を既定 ERROR + excludeVerboseContent=true に統一。stg が ALL + verbose で急増していたのを抑える。デバッグ時のみ MESH_VERBOSE_LOGS=1 で ALL に上げられる 既存ログの回収は put-retention-policy を先行実施済み(30 日)。本 PR は 恒久化。resolver 数のユニットテスト不一致 (17→15) は develop 時点で既に 失敗する別ドリフトで本変更とは無関係(logConfig のみ変更)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 85b76d1 commit 6355f6f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

infra/smalruby-mesh-v2/lib/mesh-v2-stack.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as cdk from 'aws-cdk-lib/core';
22
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
33
import * as appsync from 'aws-cdk-lib/aws-appsync';
44
import * as lambda from 'aws-cdk-lib/aws-lambda';
5+
import * as logs from 'aws-cdk-lib/aws-logs';
56
import * as route53 from 'aws-cdk-lib/aws-route53';
67
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
78
import * as targets from 'aws-cdk-lib/aws-route53-targets';
@@ -143,8 +144,17 @@ export class MeshV2Stack extends cdk.Stack {
143144

144145
xrayEnabled: stage !== 'prod',
145146
logConfig: {
146-
fieldLogLevel: stage === 'prod' ? appsync.FieldLogLevel.ERROR : appsync.FieldLogLevel.ALL,
147-
excludeVerboseContent: stage === 'prod',
147+
// stg was ALL + verbose, which grows the CloudWatch log group fast
148+
// (blew the free tier). Only escalate to ALL when explicitly debugging
149+
// via MESH_VERBOSE_LOGS=1; otherwise ERROR + exclude verbose on every
150+
// stage.
151+
fieldLogLevel: process.env.MESH_VERBOSE_LOGS === '1'
152+
? appsync.FieldLogLevel.ALL
153+
: appsync.FieldLogLevel.ERROR,
154+
excludeVerboseContent: process.env.MESH_VERBOSE_LOGS !== '1',
155+
// Cap retention so the AppSync-managed log group cannot accumulate
156+
// forever (the prod group had reached ~7.8GB with no expiry).
157+
retention: logs.RetentionDays.ONE_MONTH,
148158
},
149159
});
150160

0 commit comments

Comments
 (0)