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

Need help!!! It seems that this package can not be used in React.js #62

Closed simon-zhangmuye closed 3 years ago

simon-zhangmuye commented 3 years ago

When you call it from a standalone js file, it works. Then you try to move it in React, it cannot find Athena Object. Can anyone fix this problem?

image image

simon-zhangmuye commented 3 years ago

TypeError: AWS object not present or incorrect in the constructor

ghdna commented 3 years ago

Trying to understand your use case here. A react app is meant for browsers (i.e. anyone on the internet can read the contents of the react app) and hence its usually not a good idea to embed middleware like athena-express directly within the react app. Since invoking athena-express, requires passing an authenticated aws object, you risk exposing your aws credentials through the react app on the internet.

What you can do instead is separate out the 2 pieces: (1) AthenaExpress that is hosted on a server or FaaS (e.g. on an EC2 or Lambda if using AWS) and (2) Your react app that is hosted on a separate server (another EC2 or S3 if using AWS). And then you connect the 2 using APIs.

Happy to chat more and help you through this.

simon-zhangmuye commented 3 years ago

I can use AWS amplify to deploy the source code to AWS. So there is no risk of exposing my aws credentials.

simon-zhangmuye commented 3 years ago

I just get confused. Why there is no Athena object in a browser but works in a standalone js file?

simon-zhangmuye commented 3 years ago

Can you fix this problem and let me to use athena express in React project?

simon-zhangmuye commented 3 years ago

Athena does not support browser access.

Trying to understand your use case here. A react app is meant for browsers (i.e. anyone on the internet can read the contents of the react app) and hence its usually not a good idea to embed middleware like athena-express directly within the react app. Since invoking athena-express, requires passing an authenticated aws object, you risk exposing your aws credentials through the react app on the internet.

What you can do instead is separate out the 2 pieces: (1) AthenaExpress that is hosted on a server or FaaS (e.g. on an EC2 or Lambda if using AWS) and (2) Your react app that is hosted on a separate server (another EC2 or S3 if using AWS). And then you connect the 2 using APIs.

Happy to chat more and help you through this.