Production ALB inventory 即時重跑指令
更新日期:2026-08-03
目前執行方式
Production Athena Workgroup 的單次掃描上限是 53,687,091,200 bytes(50 GiB)。2026-08-03 實測單次 90 天查詢在到達上限時被取消,因此目前依 reviewer 決定只盤點 60 天,並拆成兩次 30 天查詢。
前 30 天 SELECT
+ 後 30 天 SELECT
→ 兩份 raw aggregate CSV 合計涵蓋 60 天
→ 對照 Legacy/New code inventory 後才合併有效 API不提高 Production Workgroup 上限。查詢排除 OPTIONS,並保留 method、normalized path、target group 與 matched rule priority。
執行前確認
執行環境是 macOS zsh,需要:
- AWS CLI profile
meite jq- Athena/Glue/S3 read 與 Athena query 權限
先確認 AWS 身分與 Workgroup:
export MIG_AWS_PROFILE='meite'
export MIG_AWS_REGION='ap-northeast-1'
aws --profile "$MIG_AWS_PROFILE" sts get-caller-identity
aws --profile "$MIG_AWS_PROFILE" \
--region "$MIG_AWS_REGION" \
athena get-work-group \
--work-group 'pro360-alb-analysis' \
--query 'WorkGroup.[Name,State,Configuration.BytesScannedCutoffPerQuery]' \
--output table \
--no-cli-pager確認 AWS account 與 IAM ARN 正確、Workgroup 是 ENABLED 才繼續。不要把 credential 或 API key 寫進文件或貼到公開訊息。
一行執行 60 天盤點
zsh '/Users/mattsu/Documents/Common Process Documents/API 路由與遷移/API Migration/pro360_api_82/正式環境上線計畫/scripts/run_production_alb_inventory_60d.zsh'腳本會自動:
- 使用昨天完整 UTC 日作為統計終點。
- 算出 60/30/7 天日期。
- 建立兩份 30 天 Athena
SELECT。 - 逐筆等待查詢完成並保存 Query execution metadata。
- 下載兩份 CSV。
- 建立 60 天 manifest,保存範圍、檔案、Query ID、狀態與掃描量。
如果第一段成功、第二段失敗,重新執行同一行會沿用已完成的第一段,不重複付費查詢。
若 manifest 已存在,腳本會停止,避免不小心重跑。只有明確需要付費重跑時才使用:
MIG_FORCE=1 zsh '/Users/mattsu/Documents/Common Process Documents/API 路由與遷移/API Migration/pro360_api_82/正式環境上線計畫/scripts/run_production_alb_inventory_60d.zsh'輸出位置
/Users/mattsu/Documents/pro360_aws_evidence/<執行日期>/production/
├── load-balancer.json
├── listeners.json
├── listener-rules.json
├── target-groups.json
├── target-health-*.json
├── production_api_inventory_60d_chunk_1.sql
├── production_api_inventory_60d_chunk_2.sql
├── production_api_inventory_<前30天>.csv
├── production_api_inventory_<前30天>.query-execution.json
├── production_api_inventory_<後30天>.csv
├── production_api_inventory_<後30天>.query-execution.json
└── production_api_inventory_<完整60天>.manifest.jsonALB snapshot 的唯讀匯出方式見 Load Balancer 唯讀匯出指令說明。若同一天已完成快照,不需要為了 Athena 重跑再次匯出。
完成判斷
最後應看到:
60 天 Athena 來源已完成
manifest: /Users/.../production_api_inventory_<起日>_to_<迄日>.manifest.json並確認兩份 query metadata 都是 SUCCEEDED,bytes_scanned 都小於 50 GiB。
2026-08-03 實測兩份 raw CSV 合計超過 760 萬列、約 1.75 GB,包含大量 bot/無效 path。不可先把所有 raw rows 載入記憶體合併;必須先對照 Legacy/New code inventory 過濾有效 API,再做 endpoint family aggregation。
同一 method/path 也可能因 API key 等條件出現多個 target/rule,因此不可直接把 CSV row 數當 API 數。要取得剩餘 API 數量,仍需合併:
最新 Legacy code inventory
+ 最新 pro360_api route/method inventory
+ listener-rules.json
+ production_api_inventory_<前30天>.csv
+ production_api_inventory_<後30天>.csv
= api_gap_inventory.csv提供下列檔案的本機路徑即可進行最後合併:
listener-rules.json
target-groups.json
production_api_inventory_<完整60天>.manifest.json
production_api_inventory_<前30天>.csv
production_api_inventory_<後30天>.csv
production_api_inventory_<前30天>.query-execution.json
production_api_inventory_<後30天>.query-execution.json原始 JSON 可能含 ARN、VPC 或內部 target 資訊,只放 evidence 目錄,不提交共用 git。