Skip to content

Instantly share code, notes, and snippets.

@pwmcintyre
Created January 21, 2022 03:49
Show Gist options
  • Save pwmcintyre/9f75a2dc3cb2ed5422fe4fc313713ce3 to your computer and use it in GitHub Desktop.
Save pwmcintyre/9f75a2dc3cb2ed5422fe4fc313713ce3 to your computer and use it in GitHub Desktop.
clone all AWS Glue tables to another database
import { Glue } from 'aws-sdk'
const glue = new Glue()
const SourceDatabaseName = "tmp"
const TargetDatabaseName = "ris-reporting"
// begin async
;(async () => {
// get tables
const tables = await glue.getTables({
DatabaseName: SourceDatabaseName,
MaxResults: 100,
}).promise()
// copy each
const names = tables.TableList.map( async (table) => {
// copy 1
await glue.createTable({
DatabaseName: TargetDatabaseName,
TableInput: {
Name: table.Name,
Description: table.Description,
Owner: table.Owner,
LastAccessTime: table.LastAccessTime,
LastAnalyzedTime: table.LastAnalyzedTime,
Retention: table.Retention,
StorageDescriptor: table.StorageDescriptor,
PartitionKeys: table.PartitionKeys,
ViewOriginalText: table.ViewOriginalText,
ViewExpandedText: table.ViewExpandedText,
TableType: table.TableType,
Parameters: table.Parameters,
TargetTable: table.TargetTable,
},
}).promise()
return table.Name
})
// done
console.log("done", { names })
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment