I'm writing a node app using typescript and the aws-sdk to call Athena. Occasionally, the call to Athena will timeout after a minute of waiting for the Athena response. The thing I don't understand is that if I go to the AWS console and look at the Athena History tab, it says my query took 4 seconds to succeed, yet in my code it runs for over a minute waiting for a response. I'm hoping there's something I'm doing wrong in my code.
myFunct... {
const athena = getAthena();
const startQueryExecutionResponse: StartQueryExecutionOutput = await athena.startQueryExecution(params).promise();
let status = "UNKNOWN";
do {
await sleep(1000);
status = await getQueryStatus(athena, startQueryExecutionResponse);
} while (status === "QUEUED" || status === "RUNNING");
return await athena.getQueryResults(startQueryExecutionResponse as GetQueryResultsInput).promise();
};
const sleep = (ms: number) => {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
};
const getQueryStatus = async (athena: AWS.Athena, startQueryExecutionResponse: Athena.StartQueryExecutionOutput): Promise<QueryExecutionState> => {
const result: GetQueryExecutionOutput = await athena.getQueryExecution(startQueryExecutionResponse as GetQueryResultsInput).promise();
console.log(result);
return result!.QueryExecution!.Status!.State || "Unknown"
};
The code gets stuck in that while loop, and I can see from the console.log below, that the status is Status: { State: 'RUNNING', SubmissionDateTime: 2019-07-23T18:28:00.639Z },
over and over again.
If the AWS console says this query took 4 seconds to complete, why does the getQueryExecution response say it's still RUNNING for minutes?