// Example usage: // $ npm i @aws-sdk/client-glue // $ DATABASE_NAME=example-database npx ts-node ./purge.ts import * as AWS from "@aws-sdk/client-glue" const client = new AWS.Glue({}) const DatabaseName = process.env['DATABASE_NAME'] // begin async ;(async () => { // get tables const tables = await client.getTables({ DatabaseName }) console.log("found tables", { DatabaseName, count: tables.TableList?.length }) if ( !tables.TableList ) { return } // process each table tables.TableList.forEach( async ({ Name }) => { // getPartitions doesn't seem to have a paginator... so we just loop until no more partitions while (true) { // get partition batch const partitions = await client.getPartitions({ DatabaseName, TableName: Name, MaxResults: 25 }) console.log("dropping", { DatabaseName, TableName: Name, partitions: partitions.Partitions?.length }) if ( !partitions.Partitions?.length ) { return } // delete batch const PartitionsToDelete: AWS.PartitionValueList[] = partitions.Partitions.map( p => ({ Values: p.Values }) ) await client.batchDeletePartition({ DatabaseName, TableName: Name, PartitionsToDelete }) } }) })()