Skip to content

Account growth in YC / AWS

Yandex Cloud, AWS and GCP expose billing/usage via API. A simple daily check:

# YC Billing API
import os, datetime, requests, subprocess
def yc_usage_today():
out = subprocess.check_output([
"yc", "billing", "billing-account", "list", "--format=json",
])
# simplified — in reality we call the Cloud Billing API REST
...
def handler(event, context):
usd = yc_usage_today()
yesterday = float(open("/tmp/yc-usd.txt").read() or "0") if os.path.exists("/tmp/yc-usd.txt") else usd
if usd > yesterday * 2 and usd > 5:
push("☁️ YC: расход вырос",
f"Сегодня: ${usd:.2f}\nВчера: ${yesterday:.2f}",
priority=9)
open("/tmp/yc-usd.txt", "w").write(str(usd))
return {"statusCode": 200}
def push(t, m, p):
requests.post(f"{os.environ['NOTIFLY_URL']}/message",
params={"token": os.environ["NOTIFLY_TOKEN"]},
json={"title": t, "message": m, "priority": p}, timeout=5)

An alternative way — Yandex Cloud can send an alert to email when a limit is exceeded. Create an Email Inbox and set it as a recipient — each such email instantly becomes a push.