athena-client - a simple aws athena client for nodejs and typescript
This is version 2.x document. 1.x document is here
Install with:
npm install athena-client
Usage Example
Create Client
var clientConfig = bucketUri: 's3://xxxx' var awsConfig = region: 'xxxx' var athena = var client = athena
Receive result by Callback
client
Receive result by Promise
client
Receive result by Stream
var stream = clientstreamstreamstreamstream
API
athena = require("athena-client")
This module exposes the createClient
and setConcurrentExecMax
method, which execute query to AWS Athena.
client = athena.createClient([clientConfig], [awsConfig])
Returns a client instance attached to the account specified by the given clientConfig
and awsConfig
.
athena.setConcurrentExecMax([concurrentExecMax])
Set the number of cuncurrent execution of query max. It should be set smaller than AWS Service limit
(default is 5).
clientConfig
object properties
Property | Default | Description |
---|---|---|
bucketUri | Required | URI of S3 bucket for saving a query results file (.csv) and a metadata file (.csv.metadata) |
pollingInterval | 1000 | Optional. Interval of polling sql results (ms) |
queryTimeout | 0 | Optional. Timeout of query execution. 0 is no timeout |
database | 'default' | Optional. The name of the database within which the query executes |
baseRetryWait | 200 | Optional. Used to calculate retry timeout for a particular query execution request |
retryWaitMax | 10000 | Optional. Maximum retry timeout for starting a new query execution |
retryCountMax | 10 | Optional. Maximum number of retry attempts for a particular query execution request |
execRightCheckInterval | 100 | Optional. Timeout when number of maximum concurrent requests is exceeded |
encryptionOption | undefined | Optional. Indicates the S3 encryption option used to encrypt the query results. Possible values include: SSE_S3 , SSE_KMS , or CSE_KMS |
encryptionKmsKey | undefined | Optional but required if encryptionOption is set to SSE_KMS or CSE_KMS . Value is the KMS key ARN or ID |
skipFetchResult | false | Optional. If true, do not return the result of the query when the athena query is finished. This option is used for CTAS |
concurrentExecMax | 5 | DEPRECATED. Use athena.setConcurrentExecMax() instead |
workGroup | 'primary' | Optional. The name of the workgroup within which the query executes |
awsConfig
object properties
Property | Default | Description |
---|---|---|
region | Required | Your Athena and S3 region |
accessKeyId | undefined | Optional. Your IAM accessKeyId |
secretAccessKey | undefined | Optional. Your IAM secretAccessKey |
client.execute([query], [callback])
It will return the following result.
If you want to know more about params of queryExecution
, please refer to the aws-sdk
document
client.execute([query]).toPromise()
Returns a Promise
that resolves the result of your query.
client.execute([query]).toStream()
Returns a Stream
to buffer the results of your query. This method is recommended for large result sets.
// Get record one by onestream // When query succeed, this event will emit.stream streamstream