-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
49 lines (45 loc) · 1.12 KB
/
index.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
var AWS = require('aws-sdk')
const athena = new AWS.Athena()
exports.startQuery = (event, context, callback) => {
const params = {
QueryString: event.query,
ResultConfiguration: {
OutputLocation: event.outputLocation
}
}
athena.startQueryExecution(params, (error, data) => {
if (error) {
callback(error)
} else {
const response = {
queryExecutionId: data.QueryExecutionId,
waitTime: 1
}
callback(null, response)
}
})
}
exports.pollStatus = (event, context, callback) => {
const params = {
QueryExecutionId: event.queryExecutionId
}
athena.getQueryExecution(params, (error, data) => {
if (error) {
callback(error)
} else {
const response = {
queryExecutionId: data.QueryExecution.QueryExecutionId,
status: data.QueryExecution.Status.State,
waitTime: event.waitTime * 2,
}
callback(null, response)
}
})
}
exports.getResults = (event, context, callback) => {
const params = {
QueryExecutionId: event.queryExecutionId,
MaxResults: 5
}
athena.getQueryResults(params, callback)
}