-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathathena-db-table-cleanup.js
52 lines (42 loc) · 1.09 KB
/
athena-db-table-cleanup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Nodejs script to Athena database cleanup to remove non used table
* Dependencies : athena-express, aws-sdk
* AWS Requried resouce: S3 bucket to store result,
* permission to delete table from athena and store result in buckets
**/
"use strict";
const AthenaExpress = require("athena-express"),
aws = require("aws-sdk"),
awsCredentials = {
region: "YOUR_REGION",
accessKeyId: "YOUR_ACCESS_KEY",
secretAccessKey: "YOUR_SECRET_KEY"
};
aws.config.update(awsCredentials);
const athenaExpressConfig = {
aws,
s3: "S3_BUCKET_PATH_TO_STORE_RESULTS",
getStats: true
};
const athenaExpress = new AthenaExpress(athenaExpressConfig);
const tblArr = ["TABLE_1_TO_DELETE","TABLE_2_TO_DELETE"]
// database name from which table need to delete
db = "default";
//Invoking a query on Amazon Athena
let droptable = async (tbl) => {
let sql1 = "DROP TABLE `" + tbl +"`;";
let myQuery = {
sql:sql1,
db: db,
getStats: true
};
try {
let results = await athenaExpress.query(myQuery);
console.log(results);
} catch (error) {
console.log(error);
}
};
tblArr.forEach(tbl => {
droptable(tbl);
});