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
181 stars 70 forks source link

Facing the 'AWS object not present or incorrect in the constructor' error even after passing the S3 location as well as the correct aws credentials #46

Closed joshis2020 closed 4 years ago

joshis2020 commented 4 years ago

I have a react app (created using create-react-app) and I have installed both the aws-sdk and athena express under the same. I passed the correct AWS credentials in the awsCredentials object and also specified a s3 path for storing the query results, but I am still getting the above error.

const AthenaExpress = require("athena-express"),
  aws = require("aws-sdk"),
  awsCredentials = {
    region: "us-east-1",
    accessKeyId: "AK******",
    secretAccessKey: "1wz**********"
  };

aws.config.update(awsCredentials);

const athenaExpressConfig = {
  aws,
  s3: "s3://shr****/queryresult/",
  getStats: true
};

const athenaExpress = new AthenaExpress(athenaExpressConfig); // this is where it fails

Below is the stack trace, I would appreciate any assistance over the same:

helpers.js:220 Uncaught TypeError: AWS object not present or incorrect in the constructor
    at Object.validateConstructor (helpers.js:220)
    at new AthenaExpress (athenaExpress.js:11)
    at Module../src/App.js (App.js:49)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/index.js (index.css?f3f6:45)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.1 (serviceWorker.js:141)
    at __webpack_require__ (bootstrap:784)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1
ghdna commented 4 years ago

Can you try with a different bucket name? And are you sure your AWS credentials are accurate?

joshis2020 commented 4 years ago

Thanks for your response, yes I can confirm that my credentials are correct. They have admin access and also I could perform various CLI commands successfully.

I also tried putting a different s3 bucket, but still the same issue.

ghdna commented 4 years ago

That seems correct. Try commenting out the validation logic and then running it. Comment out this line (line no. 11)

 helpers.validateConstructor(init);

in athena-express/lib/athenaExpress.js

joshis2020 commented 4 years ago

I tried commenting the line helpers.validateConstructor(init); and performed npm start, but it results into another issue

Uncaught TypeError: init.aws.Athena is not a constructor
    at new AthenaExpress (athenaExpress.js:13)
    at Module../src/App.js (App.js:57)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/index.js (index.css?f3f6:45)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.1 (serviceWorker.js:141)
    at __webpack_require__ (bootstrap:784)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1
ghdna commented 4 years ago

That means the aws object being passed in the athenaExpressConfig isn't correct.

joshis2020 commented 4 years ago

I see, but I am not sure where I may be going wrong in setting the credentials. Initially, I tried with cognito temporary credentials. Just to make sure, correct things are set, I hard coded them and used my user's credentials having both programmatic and console access with admin permissions. As far as the path is considered, isn't it optional? But I went ahead and tried different s3 buckets.

ghdna commented 4 years ago

Yeah the path is optional. Athena-express can create a bucket for you when you don't provide a path. Are you able to test this on a standalone node.js app, just lifting from the example?

joshis2020 commented 4 years ago

Hi,

The same code works when I test it using a standalone node.js app. Is there any compatibility issue when we use athena-express with react? I would really like to use this for my frontend dashboard :(

ghdna commented 4 years ago

There shouldn't be any compatibility issue (unless react is interfering) . But in any case, you shouldn't be calling athena-express directly from your React app because React is a client side framework and will expose your AWS object (secret/access keys) to the internet. Athena-Express is a middlewear and should be hosted on a standalone Node.js or a Lambda function, which you can then connect with React. That way your AWS object isn't exposed outside.

ghdna commented 4 years ago

Gonna close this now since its not an athena-express issue (as that works in a standalone module)