ghdna / athena-express

Athena-Express can simplify executing SQL queries in Amazon Athena AND fetching cleaned-up JSON results in the same synchronous or asynchronous request - well suited for web applications.
https://www.npmjs.com/package/athena-express
MIT License
179 stars 70 forks source link

Querying Athena using athena-express #58

Closed pabrahamusa closed 3 years ago

pabrahamusa commented 3 years ago

I am new to javascript and Athena . However trying to use athena-express with a nodejs Lambda to execute Athena Query. I am trying to enable waitForResults and get the QueryExecutionId so that I can fetch the results afterwards. I tried following code but not working..! it seems stuck at result = await p1; . As per the documentation it should return the QueryExecutionId without any latency. Appreciate any help here.

const AE = require("athena-express");
var aws = require("aws-sdk");

async function getAthenaData(query) {
  console.log(" query == " + query);

  const athenaExpressConfig = {
     aws,
     s3: "s3://sb-mydata-nonprod-logs/results",
     getStats: true,
     workgroup: "primary",
     retry: 1000,
     waitForResults: false
  };

 const athenaExpress = new AE(athenaExpressConfig);
 let p1 = athenaExpress.query(query);

 let result = "empty Query Execution ID";
 console.log(" Start resolve Promise");
 result = await p1;
 console.log(" Results after Promise === " + result);
 console.log(" End resolve Promise");
}
ghdna commented 3 years ago

the code is not structured right. Move the initializing of athena-express outside async and only execute the query within async. Follow this closely