@auth-craft/aws-cf-stack 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example CHANGED
@@ -155,6 +155,18 @@ LAMBDA_REFRESH_COOKIE_TENANT=refresh_token_tenant
155
155
  LAMBDA_REFRESH_COOKIE_SYSTEM=refresh_token_system
156
156
  LAMBDA_AUDIT_ENABLED=false
157
157
  LAMBDA_DEVICE_TRACKING=true
158
+
159
+ # ─── Observability cost controls (optional) ──────────────────────────────────
160
+ # CloudWatch Logs are billed for ingestion AND stored volume; retention only affects
161
+ # storage. Short retention in dev is the cheap default.
162
+ # Unset → 3 days in dev, 30 days in staging/prod.
163
+ # Valid → 1,3,5,7,14,30,60,90,120,150,180,365,400,545,731,1096,1827,2192,2557,
164
+ # 2922,3288,3653 (CloudWatch's fixed set — anything else fails at synth),
165
+ # or 'infinite' to never expire.
166
+ LAMBDA_LOG_RETENTION_DAYS=
167
+ # X-Ray tracing is billed per recorded trace. Unset → disabled in dev, active otherwise.
168
+ # active | disabled | pass_through
169
+ LAMBDA_TRACING=
158
170
  LAMBDA_APP_URL=
159
171
  LAMBDA_SUPPORT_EMAIL=
160
172
  LAMBDA_CORS_ORIGINS=
package/README.md CHANGED
@@ -163,6 +163,43 @@ CF_EDGE_GATE_SECRET="$SNAP_EDGE" CLOUDFLARE_ACCOUNT_ID="$SNAP_CF_ACCT" \
163
163
  npx auth-craft-stack all --stage "$STAGE"
164
164
  ```
165
165
 
166
+ ## Observability cost controls (log retention, tracing)
167
+
168
+ CloudWatch Logs and X-Ray are usually the two line items that make a low-traffic **dev**
169
+ stage cost more than the Lambda itself. Both are configurable, with stage-aware defaults
170
+ that keep dev cheap without touching staging/prod behaviour:
171
+
172
+ | Setting | Env var / flag | Default (dev) | Default (staging/prod) |
173
+ |---------|----------------|---------------|------------------------|
174
+ | Log retention | `LAMBDA_LOG_RETENTION_DAYS` / `--log-retention-days` | `3` days | `30` days |
175
+ | X-Ray tracing | `LAMBDA_TRACING` / `--tracing` | `disabled` | `active` |
176
+
177
+ ```bash
178
+ # Cheapest dev: keep 1 day of logs, no tracing (tracing is already off by default in dev)
179
+ npx auth-craft-stack lambda --stage dev --log-retention-days 1
180
+
181
+ # Turn tracing back on in dev while debugging
182
+ npx auth-craft-stack lambda --stage dev --tracing active
183
+
184
+ # Long retention for an audited prod
185
+ npx auth-craft-stack lambda --stage prod --log-retention-days 365
186
+ ```
187
+
188
+ Notes:
189
+ - Retention accepts only **CloudWatch's fixed set** — `1, 3, 5, 7, 14, 30, 60, 90, 120, 150,
190
+ 180, 365, 400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, 3653` — or `infinite` to never
191
+ expire. Any other value fails at **synth** time with the valid list, so a typo can't
192
+ silently deploy the wrong retention.
193
+ - Retention caps **storage** cost only; you are still billed for log **ingestion**. To cut
194
+ ingestion, reduce what the app logs.
195
+ - Changing retention applies to the existing log group too (it's the same CloudFormation
196
+ resource), so old logs beyond the new window age out — it is not just for new logs.
197
+ - In `prod` the log group has `RemovalPolicy.RETAIN`, so destroying the stack keeps the logs
198
+ (and the group must be deleted manually before a same-name redeploy). In dev/staging it is
199
+ destroyed with the stack.
200
+ - `LogRetentionDays` and `TracingMode` are emitted as CDK outputs, so
201
+ `npx auth-craft-stack outputs` shows what is actually deployed.
202
+
166
203
  ## CORS (per scope + dynamic allowlist)
167
204
 
168
205
  CORS is resolved **per scope** (system / tenant / customer) — the 3 workers no longer