Skip to content

QA plan: CloudWatch log groups and alarm routing (#34)

Story: CloudWatch logging and basic metrics (#34)
Capability: Cost guardrails and observability (#31)
ADRs: RAG020 (observability); RAG009 (log scrub)
Security requirements: per-feature requirements, Feature 31/32/33/34 (log scrub, alarm subscriber); Feature 19/20/21/22/23/24/25 (retention)

Logger usage, request-ID correlation, logged content, and EMF metrics are tested in plan-observability. Alarm thresholds and the kill switch are tested in plan-budgets. This plan covers the log groups and the alert topic they depend on.

TypeCoverage
IaC (plan review)Every aws_cloudwatch_log_group sets retention_in_days = 30 explicitly. No log group relies on default infinite retention.
IaC linttfsec rule: retention_in_days is present and non-zero on all aws_cloudwatch_log_group resources.
IaC (plan review)Each environment root defines log groups for the API Lambda, the authorizer Lambda, and the API Gateway access log, and each Lambda writes to its own group.
IaC (plan review)Every alarm in each environment root has its alarm action and OK action set to the rag-sample-alerts topic ARN from the bootstrap root.
Integration (manual, QA)After a POST /query call with a per-run QA key, a Logs Insights query across the API, authorizer, and access log groups returns no record containing the Authorization header under any casing, the key’s token string, or the key secret. A query on the request ID returns a record in the API log group, so the check is not vacuous.
Integration (manual, QA)aws logs describe-log-groups lists the API, authorizer, and access log groups for rag-sample-qa with retentionInDays of 30.
Integration (manual, QA)The rag-sample-alerts topic has at least one subscription in Confirmed state, and a test publish from the spend and abuse runbook reaches the operator’s inbox.
Integration (manual, QA)Each QA alarm is in OK state with no errors present.
  • #23 (Lambda and API Gateway) and #60 (authorizer) deployed to QA
  • Story #25 (IAM) complete so the Lambdas can write to CloudWatch
  • Story #385 (alert topic and alarms) complete
  • Terraform plan for each environment shows the log groups, 30-day retention, and alarm actions listed in Test scope, and tfsec passes.
  • Integration checks for every Integration row in Test scope pass against QA.
  • Each requirement in Security requirements below is verified by the test named in its row.

IaC: CI. Integration: manual against QA.

tfsec, Terraform plan output, AWS CLI (aws logs describe-log-groups, aws logs start-query, aws logs get-query-results, aws sns list-subscriptions-by-topic, aws cloudwatch describe-alarms), CloudWatch Logs Insights console.

Integration check, run in the Logs Insights console or with aws logs start-query against the three QA log groups, after log ingestion completes:

fields @timestamp, @message
| filter @message like /(?i)("authorization"\s*:|Bearer\s)/ or @message like /<minted key token>/
| sort @timestamp asc

The test run inserts its own api_keys row (bounded by quota and expiry, per the CI key pattern in RAG009), sends the request with that key, and deletes the row at the end. A fake token is denied by the authorizer before the API Lambda runs, so only a valid key exercises the API log group. The scrub query also filters for the minted key’s token string and returns zero rows. A second query on the request ID of the call returns at least one record in the API log group; zero records there fails the check.

Terminal window
aws logs describe-log-groups --query "logGroups[?contains(logGroupName, 'rag-sample-qa-')].[logGroupName,retentionInDays]" --output table

Every row shows 30.

  • Logs Insights ingestion lags by several minutes. Run the scrub query after the lag, not immediately after the request.
  • A log group that Lambda creates on first invocation has infinite retention. The Terraform group must exist before the first invocation, and the plan review checks that each Lambda has one.
  • An unconfirmed SNS subscription delivers nothing and raises no error. The subscription state check is the only detection.
RequirementVerified bySource
The Authorization header and key material are absent from every log group under any casing.Integration Logs Insights scrub query with a per-run QA key, plus a request-ID query confirming the API log group has a record for the call; unit scrub test in plan-observabilityFeature 31/32/33/34; RAG009
Every log group has explicit, finite 30-day retention.IaC plan review; tfsec; describe-log-groupsFeature 19/20/21/22/23/24/25; Decisions log D-8
Alarms publish to the alert topic, and the topic has a confirmed subscriber.IaC plan review; subscription state checkFeature 31/32/33/34; RAG020

RAG020: explicit log retention per environment, and CloudWatch alarms publishing to one SNS topic that emails the operator. RAG009: Authorization header scrubbed from logs. D-8: 30-day retention. Security requirements: scrub and alarm with subscriber (Features 31/32/33/34), and retention (Features 19/20/21/22/23/24/25). Exit criteria cover each.