-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.js
38 lines (35 loc) · 1.19 KB
/
query.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
const AWS = require('aws-sdk');
AWS.config.update({region:'us-east-1'});
const athena = new AWS.Athena();
function queryData(query,callback) {
const params = {
QueryString: query, /* required */
ResultConfiguration: { /* required */
OutputLocation: 's3://aws-athena-query-results-089961381921-us-east-1/', /* required */
EncryptionConfiguration: {
EncryptionOption: 'SSE_S3' /* required */
}
},
QueryExecutionContext: {
Database: 'indydata'
}
};
athena.startQueryExecution(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
const pollDB = setInterval(function() {
athena.getQueryResults({QueryExecutionId: data.QueryExecutionId}, function(err1, results) {
if (err1) {
if( err1.code != 'InvalidRequestException') {
console.log(err1, err1.stack);
}
}
else {
callback(err1,results.ResultSet.Rows);
clearInterval(pollDB);
}
});
},1000)
});
}
module.exports.queryData = queryData;