aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
2.96k stars 556 forks source link

SignatureDoesNotMatch #6163

Open VincentSurelle opened 3 weeks ago

VincentSurelle commented 3 weeks ago

Checkboxes for prior research

Describe the bug

Hello,

Following the issue #5192 and the workaround provided by @trivikr

If I take this case :

// ...
const client = new SSM();
const secret = client.getSecretValue(params); // Don't want to await there since it will extends my cold start time

const handler = async (event) => {
  // Do some stuff
  // More stuff that can take some time
  // Now I need it so I can await it
  doSomethingWithMySecret(await secret); // Perfect timing, there's more chances that my Promise is already resolved
}

Is this still possible with SDK v3 ?

Thanks :)

SDK version number

v3

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

20

Reproduction Steps

const client = new SSM();
const secret = client.getSecretValue(params); // Don't want to await there since it will extends my cold start time

const handler = async (event) => {
  // Do some stuff
  // More stuff that can take some time
  // Now I need it so I can await it
  doSomethingWithMySecret(await secret); // Perfect timing, there's more chances that my Promise is already resolved
}

Observed Behavior

An SignatureDoesNotMatch Error is throwed sometimes (Auto Provisioning)

Expected Behavior

No error

Possible Solution

No response

Additional Information/Context

No response

aBurmeseDev commented 2 weeks ago

Hi @VincentSurelle - thanks for reaching out.

I'm not sure what your workflow looks like but if you're not using TLA (Top Level Await) in your application, you can consider moving API call inside the handler, although not recommended. If you could share your workflow and repro code, I'd be happy to further look into it.

VincentSurelle commented 1 week ago

Hello !

I don't think I can give more details with a repro than the code I show in the first message :

// ...
const client = new SSM();
// Here we are outside the handler -> During the cold start
// We start a promise -> Don't need to await it there since I won't need it now and don't want to extend cold start duration
// This way, promise is fired up, if cold start take, for example, 200ms after this line, that's 200ms earned on the request duration
const secret = client.getSecretValue(params);

const handler = async (event) => {
  // Here i do some unrelated stuff that can take some time or no. Just unrelated stuff
  doSomething();
  doSomethingElse():
  // Here, I need my secret.
  // Promise was started during cold start. Maybe 10ms before. Maybe 100 or event 1000ms or 10 minutes ? Whatever
  // But since I await my promise here. I have way more chances that it has been resolved.
  // That some precious ms
  doSomethingWithMySecret(await secret); // But if it's more than somes minutes after promise startup. The exception occurs
}

Now the problem appear with SDK V3

If it was a simple request like axios.get('https://amazon.com'). No trouble SDK V2 was ok with this.

SDK V3 is not