# LATAM Tenants Summary Task

Handler: `summary_function.lambda_handler`

This daily Lambda reads the LATAM target database and sends one Feishu card with
accurate aggregate totals plus up to 10 detail rows for each section:

- P0 tenants;
- P1 tenants;
- LATAM tenants with successful import events in the last seven days.

The aggregate block also reports the number of scoped tenants with at least
one ICP match. Tenant detail lines render the canonical categories as Fintech,
Retail, E-Commerce, AI, and iGaming labels so the reason for the Fit boost is
visible to reviewers.

Active tenant sections use the same stock scope as the Dispatcher: active,
external, `sales_force_region = 'LATAM'`, and excluding plans
`free_trial`, `new_user`, and `closing`. The aggregate previous-day signup,
non-individual signup, and AI-related signup counts use
`country_region = 'LATAM'` and are selected by `created_at`; they do not depend
on mutable `source_type`. Non-individual includes only the recognized company
and institution categories; `individual`, `unknown`, empty, and unrecognized
classifications are excluded.

The Summary does not call Qwen or calculate scores. Scoring is owned by
`LATAM-Tenants-Scoring-Task`.

`tenant_avg_qps = NULL` is rendered as `N/A`, while a measured zero is rendered
as `0`.

## Configuration

Required:

- `TARGET_DATABASE_URL`, or the `TARGET_DB_*` variables;
- `FEISHU_WEBHOOK_URL`, injected through the `NoEcho` CloudFormation parameter
  at deploy time rather than stored in source control.

Optional:

- `TARGET_TIDB_SSL_CA_PATH` or `TIDB_SSL_CA_PATH`;
- `IMPORT_EVENT_COUNT_TABLE` (default `latam_tenant_events`);
- `SUMMARY_SECTION_LIMIT` (default 10).

Weekly Metrics and Summary should receive the same LATAM Feishu webhook value.
The Lambda role does not need runtime Secrets Manager access; the database
account only needs read access to the LATAM reporting tables.
