1.0.8 • Published 6 years ago

aws-athena-client v1.0.8

Weekly downloads
6
License
-
Repository
github
Last release
6 years ago

Build Status Coverage Status

athena-client - a nodejs simple aws athena client

Install with:

npm install athena-client

Usage Example

var credentials = {
    accessKeyId: 'xxxx',
    secretAccessKey: 'xxxx',
    region: 'xxxx',
}
var config = {
    bucketUri: 's3://xxxx'
}
 
var Athena = require("athena-client")
var client = Athena.Client(credentials, config)
 
client.execute('SELECT 1', function(err, data) {
    if (err) {
        return console.error(err)
    }
    console.log(data)
})
 
// You can also execute query with promises
client.execute('SELECT 1').then(function(data) {
    console.log(data)
}).catch(function(err) {
    console.error(err)
})

API

athena = require("athena-client")

This module exposes the Client method, which execute query to AWS Athena

client = athena.Client(credentials, config)

Returns a client instance attached to the account specified by the given credentials and config.

The credentials can be specified as an object with accessKeyId and secretAccessKey and region members such as the following:

var credentials = {
    accessKeyId: 'xxxx',
    secretAccessKey: 'xxxx',
    region: 'xxxx',
}

config object properties

PropertyDefaultDescription
bucketUrlRequiredURI of S3 bucket for saving a query results file(.csv) and a metadata file (.csv.metadata)
pollingInterval1000Interval of polling sql results (ms)
queryTimeout0Timeout of query execution. 0 is no timeout
format'array'If 'array', the result of the query is as the following [ { _col0: '1' } , { _col0: '2' }] . If 'raw', the result of query is same with aws-sdk
concurrentExecMax5The number of cuncurrent execution of query max. it should be set smaller than AWS Service limit(default is 5)

client.execute(query, options, callback)

Returns query result. The options can be specified as an object with timeout and format members such as the following:

var options = {
    timeout: 3000,
    format: 'raw',
}
client.execute('SELECT 1', function(err, data) {
    if (err) {
        return console.error(err)
    }
    console.log(data)
})

client.execute('SELECT 1', {timeout: 3000}, function(err, data) {
    if (err) {
        return console.error(err)
    }
    console.log(data)
})

client.execute('SELECT 1').then(function(data) {
    console.log(data)
}).catch(function(err) {
    console.error(err)
})