Skip to content

Commit b78d13f

Browse files
authored
Merge pull request #1103 from smalruby/fix/mesh-v2-appsync-log-retention
fix(mesh-v2): appsync ログの retention 設定と既定ログレベル抑制 (CloudWatch 費用)
2 parents 85b76d1 + 6355f6f commit b78d13f

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)