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

Don't re-instantiate defaultProvider() in each interceptor #159

Open
ndowmon opened this issue Jul 20, 2023 · 1 comment
Open

Don't re-instantiate defaultProvider() in each interceptor #159

ndowmon opened this issue Jul 20, 2023 · 1 comment

Comments

@ndowmon
Copy link

ndowmon commented Jul 20, 2023

It seems that the awsV4Signature() function is loaded as an axios request interceptor in @lifeomic/alpha, which (I think) means that the function is invoked on each request. Since a new instance of defaultProvider() is instantiated at https://github.com/LifeOmic/alpha/blob/master/src/interceptors/aws-v4-signature.ts#L68, each lambda call is re-instantiating those credentials - meaning, re-invoking the ECS container metadata endpoint, if loading from ECS (or EC2).

It would be better if @lifeomic/alpha instantiated defaultProvider() just one time and re-used the same credential provider in the interceptor.

e.g.

+const DEFAULT_CREDENTIAL_PROVIDER = defaultProvider();
 const awsV4Signature: AlphaInterceptor = async (config) => {
   
   ...

   const {
-    credentials = defaultProvider(),
+    credentials = DEFAULT_CREDENTIAL_PROVIDER,

See https://github.com/JupiterOne/sdk/pull/930/files#r1270091324


Also, I'd recommend setting default retries in the defaultProvider(), like so:

-const DEFAULT_CREDENTIAL_PROVIDER = defaultProvider();
+const DEFAULT_CREDENTIAL_PROVIDER = defaultProvider({ maxRetries: 3 });
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

Successfully merging a pull request may close this issue.

2 participants