Reputation: 319
Upvotes: 5
Views: 11238
Reputation: 1
This is code about node js with Athena connection....
const AthenaExpress = require("athena-express");
const aws = require("aws-sdk");
const awsCredentials = {
region: "us-east-1",
accessKeyId: "xxxxx", // Modified key name
secretAccessKey: "xxxxxxxxx", // Modified key name
};
aws.config.update(awsCredentials);
const athenaExpressConfig = {
aws: aws,
s3: "s3://xyz/abc/",
getStats: true,
};
const athenaExpress = new AthenaExpress(athenaExpressConfig);
(async () => {
let myQuery = {
sql: "SELECT id, name, address FROM dummydata1ealogs LIMIT 3",
db: "database",
};
try {
let results = await athenaExpress.query(myQuery);
console.log(results);
} catch (error) {
console.log(error);
}`enter code here`
})();
Upvotes: 0
Reputation: 890
You need to use aws-sdk and athena-express dependencies,
There's a full working tutorial in this video I made: https://www.youtube.com/watch?v=aBf5Qo9GZ1Yac
Upvotes: 0
Reputation: 2477
You could use the athena-express module from here, as documented by AWS here
Upvotes: 2
Reputation: 167
I am using athena like following way in my nodejs project :
download JDBC driver from AWS. Create a connector.js file. npm install jdbc NPM. Paste followings:
var JDBC = require('jdbc');
var jinst = require('jdbc/lib/jinst');
if (!jinst.isJvmCreated()) {
jinst.addOption("-Xrs");
jinst.setupClasspath(['./AthenaJDBC41-*.jar']);
}
var config = {
// Required
url: 'jdbc:awsathena://athena.*.amazonaws.com:443',
// Optional
drivername: 'com.amazonaws.athena.jdbc.AthenaDriver',
minpoolsize: 10,
maxpoolsize: 100,
properties: {
s3_staging_dir: 's3://aws-athena-query-results-*/',
log_path: '/logs/athenajdbc.log',
user: 'access_key',
password: 'secret_key'
}
};
var hsqldb = new JDBC(config);
hsqldb.initialize(function(err) {
if (err) {
console.log(err);
}
});
Upvotes: 4