MonthToDateUsage icon
Usage icon
Script icon
Process icon
If icon
SlackIncomingWebhook icon
Log icon
DiscordIncomingWebhook icon
Schedule icon

Fastly Month-to-Date Cost Guard

Catch Fastly bill surprises mid-month with Kestra. Pull month-to-date usage, compute bandwidth in GB, and alert Slack when it crosses a threshold.

Categories
CloudInfrastructure

CDN bills surprise people because usage is invisible between invoices: a traffic spike, a misconfigured cache, or an unpurged asset loop can run for weeks before anyone sees a number. This blueprint checks the number that becomes the invoice while the month is still running. io.kestra.plugin.fastly.stats.MonthToDateUsage pulls the account's month-to-date rollup, io.kestra.plugin.fastly.stats.Usage with byService: true attaches the per-service breakdown, and a small Python step reduces the payload to one scalar, total bandwidth in GB, that an If task compares against your threshold. Over it, Slack gets a warning with the measured number while there is still time to react.

How it works

  1. month_to_date (io.kestra.plugin.fastly.stats.MonthToDateUsage) fetches the account's usage rollup for the current billing month.
  2. usage_by_service (io.kestra.plugin.fastly.stats.Usage) fetches the window from the first of the month to today with byService: true, so the execution carries the answer to "which service is doing this" alongside the total.
  3. compute_bandwidth (io.kestra.plugin.scripts.python.Script on the io.kestra.plugin.core.runner.Process runner) receives the month-to-date data output as JSON through an environment variable, walks the structure summing every bandwidth field, converts bytes to GB, and emits the scalar through Kestra's outputs protocol as bandwidth_gb.
  4. check_threshold (io.kestra.plugin.core.flow.If) compares the scalar with the bandwidth_threshold_gb input. Over the threshold, alert_overage posts the measured number to Slack; under it, log_ok records a healthy check.
  5. The errors block posts a Discord alert when the guard fails, because a dead cost check is indistinguishable from a cheap month.
  6. A disabled-by-default weekly Schedule trigger runs the guard every Monday morning.

What you get

  • A mid-month look at the number the invoice is built from, instead of a month-end surprise.
  • One scalar to reason about, with the raw month-to-date and per-service payloads preserved on the execution.
  • A threshold that lives in an input, adjustable per environment without editing the flow.
  • An alert with the measured GB and the limit side by side, plus a pointer to the per-service breakdown.

Who it's for

  • Platform and infrastructure teams who own the Fastly account and answer for its line item.
  • Engineering leaders who have been surprised by a CDN invoice at least once.
  • FinOps teams adding usage checks to services that only report costs monthly.

Why orchestrate this with Kestra

Fastly exposes month-to-date usage through its API, but an API nobody polls prevents nothing. Kestra provides the loop around it: a schedule, retries on flaky calls, a Python step for the arithmetic with no infrastructure of its own thanks to the Process runner, a branch that separates alerting from logging, and an execution history that becomes a week-by-week record of the month's trajectory.

Prerequisites

  • A Fastly API token able to read stats and usage.
  • A Slack incoming webhook for cost alerts and a Discord webhook for failure alerts, or point both at the same team by swapping tasks.
  • Python 3 available on the Kestra host, since the script uses the Process runner; switch to a Docker task runner if the host has no Python.

Secrets

  • FASTLY_API_TOKEN: Fastly API token with stats read access.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL.
  • DISCORD_WEBHOOK_URL: Discord incoming webhook URL.

Quick start

  1. Add the three secrets to your Kestra namespace.
  2. Execute the flow once and read the computed GB from the logs, then set bandwidth_threshold_gb a sensible margin above your normal month.
  3. Set disabled: false on the weekly trigger.

How to extend

  • Sum requests instead of bandwidth by changing one key in the Python walk, or emit both scalars and gate on either.
  • Alert on the fastest-growing service by having the script also parse the usage_by_service output.
  • Tighten the cadence to daily near the end of the month by adjusting the cron expression.
  • Pair with the daily traffic digest blueprint so volume trends and cost checks land in the same channel.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.