#!/bin/env zx
import fs from "fs"

const regions = JSON.parse(await $`aws ec2 describe-regions`).Regions.map(r => r.RegionName);

console.log("Available regions:", regions);

for (const region of regions) {
    console.log("Fetching instances for region", region)
    console.log(JSON.parse(await $`aws ec2 describe-instances --region ${region}`).Reservations.flatMap(r => r.Instances).filter(i => i.State.Name !== "terminated"))
}
