Cut your Fly.io bill by stopping dev Machines overnight

By General Input

Every weeknight at 8pm, automatically stop your idle dev and staging Fly.io Machines, log each one to a spreadsheet, and post a single Slack recap.

Integrations

  • Fly.io
  • Google Sheets
  • Slack Bot

Type

Deterministic Code

Categories

  • Engineering
  • Operations

Every weeknight (Monday through Friday) at 8pm, run this workflow to cut my Fly.io bill by shutting down non-production Machines overnight. This is fully deterministic: scan, filter by tag, stop, log, and summarize. Never touch production Machines. Use a cron trigger, since Fly.io has no webhook or poll trigger.

Step 1 — Scan. List all of my Fly.io Machines across the organization. Use the Fly.io List All Machines operation to get every Machine in the org in a single pass. If only an app-scoped token is available, fall back to List Apps and then call List Machines for each app. For each Machine, capture its app name, Machine ID, region, current state, and metadata.

Step 2 — Filter by tag. Read each Machine's metadata (for example an env or environment label). If that label is not present on the list response, call Get Metadata for the Machine to read it. Keep only Machines whose environment label is dev or staging (case-insensitive) AND whose current state is started. Explicitly skip any Machine labeled production or prod, and skip any Machine that has no environment label at all. When in doubt, leave it running. Never stop a production Machine.

Step 3 — Stop. For each remaining Machine, call Stop Machine to power it off. Only currently started Machines are eligible, so already-stopped Machines are skipped and never produce errors. Respect Fly.io rate limits (roughly one request per second per action) when stopping many Machines.

Step 4 — Log. After stopping each Machine, append one row to a Google Sheets audit log using the Append Values operation so there is a durable trail. Each row should contain, in order: timestamp (the run time in ISO 8601), app name, Machine ID, region, and action (the literal value stopped). Append rows after the last row of the configured log tab.

Step 5 — Summarize. Once the scan is complete, post a single end-of-run summary to Slack using the Slack Bot Send a Message operation. The message should state how many Machines were stopped and break the count down by app, for example: Stopped 4 Machines overnight — my-api-staging (2), my-web-dev (2). Post the summary even when nothing was stopped, so I always know the run completed. Send it to the Slack channel I configure.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentLocal listing health board for every location you manageLet support send one-off Loops emails without an engineerA brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensStop cold emails to anyone with a live deal in PipedriveLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasoniMessage campaign console with pre-flight checks and delivery board