Created
January 21, 2022 03:49
-
-
Save pwmcintyre/9f75a2dc3cb2ed5422fe4fc313713ce3 to your computer and use it in GitHub Desktop.
clone all AWS Glue tables to another database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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