Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global config issue #56

Open
aliccer opened this issue Aug 9, 2019 · 5 comments
Open

Global config issue #56

aliccer opened this issue Aug 9, 2019 · 5 comments

Comments

@aliccer
Copy link

aliccer commented Aug 9, 2019

I spent a lot of time trying to find a problem in my code but the problem was hidden from the eyes, and it lives on this line of code https://github.com/KoteiIto/node-athena/blob/master/src/index.ts#L42

I am using AWS STS to be able to access another AWS profile, and run a request with temporary credentials that are passed to the createClient function and they are set globally after the function call, and it breaks the rest of the AWS client calls (like S3, where default server settings must be used) returning in the response Access Denied

@phasath
Copy link

phasath commented Aug 15, 2019

@aliccer I have the same problem as I access many things on AWS from different regions. The fix would be just receiving an AWS client and then, creating new clients with the correct region as seen here:

https://stackoverflow.com/a/40366746/2569522

@aliccer
Copy link
Author

aliccer commented Aug 15, 2019

@phasath thank you for the response but it is not the same thing, take a look at the simple example below

const AWS = require("was-sdk")
const athena = require("athena-client")

new AWS.STS.assumeRole(/*params*/).then((credentials) => {
   // when the Athena Client instance created it writes assumed role to the global AWS config
   const athenaClient = athena.createClient(credentials)

   // and when the S3 bucket instance created it must use default server config
   // but instead it takes config which was reconfigured by `athena-client`
   const s3Bucket = new AWS.S3()
})

So to make my S3 client to look at the production AWS profile I must explicitly pass the server config into S3 (like this new AWS.S3(defaultConfig)), like you did in your example, but this is not the right way in my case, because AWS clients must use the server config respectively if they were created without arguments

@phasath
Copy link

phasath commented Aug 15, 2019

@aliccer oh, sorry. I didn't mean it as a way to fix your problem.

I forgot to break line. I believe the fix should be done on the athena-client by either accepting a new AWS client or creating a new AWS client inside the athena-client (without changing the global one).

@aliccer
Copy link
Author

aliccer commented Aug 15, 2019

@phasath I forked the package and in my example removed this line https://github.com/KoteiIto/node-athena/blob/master/src/index.ts#L42 and add config into Athena and S3 instances like this

const athena = new Athena(Object.assign({ apiVersion: '2017-05-18' }, awsConfig))
const s3 = new S3(Object.assign({ apiVersion: '2006-03-01' }), awsConfig)

and it fixes the issue

@phasath
Copy link

phasath commented Aug 15, 2019

@aliccer I forked and changed it too to allow a overwrite flag

https://github.com/phasath/node-athena

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants