================================================================
CloudWatch Logs ／ /aws/lambda/monthly-report-batch（架空）
================================================================

[2026-05-01 02:00:01.234] START RequestId: 4f8a-... Version: $LATEST
[2026-05-01 02:00:01.456] INFO  monthly_report.handler: バッチ開始 target_month=2026-04
[2026-05-01 02:00:02.012] INFO  monthly_report.handler: DB 接続開始 host=aurora-prod.cluster-xxx.ap-northeast-1.rds.amazonaws.com
[2026-05-01 02:00:02.345] INFO  monthly_report.handler: DB 接続成功
[2026-05-01 02:00:02.567] INFO  monthly_report.fetch_contracts: アクティブ契約数 取得中
[2026-05-01 02:00:03.123] INFO  monthly_report.fetch_contracts: アクティブ契約数 = 142,853 件
[2026-05-01 02:00:04.890] INFO  monthly_report.aggregate: 集計処理 開始
[2026-05-01 02:00:35.234] WARN  monthly_report.aggregate: メモリ使用量が閾値を超えました MEMORY=2980MB / LIMIT=3008MB
[2026-05-01 02:00:42.567] ERROR monthly_report.aggregate: メモリエラー発生
Traceback (most recent call last):
  File "/var/task/monthly_report/aggregate.py", line 87, in aggregate_by_department
    department_summary[dept] = pandas.DataFrame(records).groupby(['age_group','dept']).sum()
  File "/var/runtime/pandas/core/frame.py", line 1234, in __init__
    arr = np.empty((nrows, ncols), dtype=object)
MemoryError: Unable to allocate 2.34 GiB for an array with shape (142853, 17) and data type object

[2026-05-01 02:00:42.589] ERROR monthly_report.handler: 集計処理失敗
Traceback (most recent call last):
  File "/var/task/monthly_report/handler.py", line 45, in handler
    summary = aggregate_by_department(contracts)
  File "/var/task/monthly_report/aggregate.py", line 87, in aggregate_by_department
    department_summary[dept] = pandas.DataFrame(records).groupby(['age_group','dept']).sum()
MemoryError: Unable to allocate 2.34 GiB for an array with shape (142853, 17) and data type object

[2026-05-01 02:00:42.612] ERROR monthly_report.handler: 例外を上位へ伝播
[2026-05-01 02:00:42.634] END RequestId: 4f8a-...
[2026-05-01 02:00:42.634] REPORT RequestId: 4f8a-... Duration: 41400.23 ms Billed Duration: 41401 ms Memory Size: 3008 MB Max Memory Used: 3008 MB Init Duration: 234.56 ms

================================================================
追加情報（人間メモ、架空）
================================================================
- 先月（2026-04-01 早朝）までは正常稼働
- 2 週間前（2026-04-15 頃）に「集計処理を pandas に置き換えるリファクタ」がマージされた
- アクティブ契約数は前月から 12% 増加（127,012 → 142,853）
- Lambda のメモリ設定は 3008MB のまま、過去 1 年変更なし
- 同じコードをローカル開発機（メモリ 16GB）で実行すると正常完了する
