AWS Athena Client for NodeJS
Installation
Using NPM:
npm install aws-athena-node-client
Using yarn:
yarn add aws-athena-node-client
Use
Create client
const athenaClient = new AthenaClient({
awsConfig: {
accessKeyId: 'DASCDAS82941',
apiVersion: '2017-05-18',
region: 'eu-west-1',
secretAccessKey: 'CJDADDHDASIUOHADS/3123DASE12',
},
bucketUri: 's3://athena-query-results-eu-west-1/',
database: 'default',
waitTime: 0.5,
workGroup: 'my-work-group',
});
Run query
Javascript
const query = `SELECT 1`;
athenaClient.executeQuery(query)
.then((results) => {
console.log(results);
})
.catch((error) => {
console.error(error);
});
Typescript
const query = `SELECT 1`;
try {
const results = await athenaClient.executeQuery<T>(query);
console.log(results);
} catch (error) {
console.error(error);
}
Run query and get S3 URL with results
const query = `SELECT 1`;
athenaClient.executeQueryAndGetS3Url(query)
.then((s3Url) => {
console.log(s3Url);
})
.catch((error) => {
console.error(error);
});
Typescript
const query = `SELECT 1`;
try {
const results = await athenaClient.executeQueryAndGetS3Url(query);
console.log(results);
} catch (error) {
console.error(error);
}
Cancel query
const query = `SELECT 1`;
athenaClient.executeQuery(query, parameters, 'hdaiuh33r8uyjdkas')
.then((results) => {
console.log(results);
})
.catch((error) => {
if (!(error instanceof QueryCanceledException)) {
console.error(error);
}
});
Typescript
const query = `SELECT 1`;
try {
const results = await athenaClient.executeQuery<T>(query, parameters, 'hdaiuh33r8uyjdkas');
console.log(results);
} catch (error) {
if (!(error instanceof QueryCanceledException)) {
console.error(error);
}
}
You must run this code in a distinct thread than the query execution thread.
athenaClient.cancelQuery('hdaiuh33r8uyjdkas')
.then((results) => {
})
.catch((error) => {
console.error(error);
});
Typescript
try {
await athenaClient.cancelQuery('hdaiuh33r8uyjdkas');
} catch (error) {
console.error(error);
}