From 396e3d68086d8a09a312f1e0ed080df8b2fd076d Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sun, 10 May 2026 03:06:16 +0700 Subject: [PATCH] feat(deploy): cold-start metric filter + trading module in SAM template - Add AWS::Logs::MetricFilter for Lambda cold-start detection - Wire trading module into template.yaml MODULES default list --- template.yaml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/template.yaml b/template.yaml index 4672193..87e55ba 100644 --- a/template.yaml +++ b/template.yaml @@ -14,7 +14,7 @@ Parameters: ModulesCSV: Type: String - Default: util,misc,wordle,loldle,loldle-ability,loldle-emoji,loldle-quote,loldle-splash,lolschedule,semantle,doantu,twentyq + Default: util,misc,wordle,loldle,loldle-ability,loldle-emoji,loldle-quote,loldle-splash,lolschedule,semantle,doantu,twentyq,trading Description: Comma-separated module names enabled at runtime (matches MODULES env). BotOwnerID: @@ -89,6 +89,21 @@ Resources: LogGroupName: !Sub "/aws/lambda/${AWS::StackName}-bot" RetentionInDays: 7 + # Lambda emits a synthetic REPORT line at the end of every invocation. + # On a cold start that line includes "Init Duration: ". This filter + # parses that field into a custom metric so the AWS-port plan's "P95 < 1.5s" + # cold-start abort criterion is observable from day one. + ColdStartMetricFilter: + Type: AWS::Logs::MetricFilter + Properties: + LogGroupName: !Ref BotFunctionLogGroup + FilterPattern: '[report="REPORT", reqid_label="RequestId:", reqid, dur_label="Duration:", dur, dur_unit="ms", bill_label="Billed", bill_dur_label, bill_dur, bill_unit, mem_label, mem_size_label, mem_size, mem_unit, max_label="Max", max_used_label="Memory", max_used_label2="Used:", max_used, max_used_unit, init_label="Init", init_dur_label="Duration:", init_dur, init_unit="ms"]' + MetricTransformations: + - MetricName: ColdStartInitDuration + MetricNamespace: miti99bot + MetricValue: $init_dur + Unit: Milliseconds + BotFunction: Type: AWS::Serverless::Function DependsOn: BotFunctionLogGroup