aws-sdk-js-codemod icon indicating copy to clipboard operation
aws-sdk-js-codemod copied to clipboard

S3 waitFor adding extra delay which changes application behavior

Open abhirpat opened this issue 2 years ago • 5 comments
trafficstars

Self-service

  • [ ] I'd be willing to implement a fix

Describe the bug

SDK V2 to V3 migration using codemod is adding extra time which is causing performance issues.

await s3.waitFor('objectExists', param).promise();

transformed by codemod

await waitUntilObjectExists({
           client: s3,
           maxWaitTime: 200
       }, param)

The codemod adds maxWaitTime: 200 which is changing the code behavior and causing performance issues

Steps to reproduce

Try to reproduce using the provided description for command.

Observed behavior

The command waits for 200 seconds which is adding significant delay.

Expected behavior

The code would execute instantly before.

Environment

aws-sdk-js-codemod: 0.26.3
- jscodeshift: 0.15.0
- recast: 0.23.4

Additional context

No response

abhirpat avatar Nov 20 '23 19:11 abhirpat

The maxWaitTime does not cause any performance issues. It's just a default value which is required in JS SDK v3 waiters. More details in https://github.com/awslabs/aws-sdk-js-codemod/issues/53#issuecomment-1366081340

Would adding the following comment help?

await waitUntilObjectExists({
   client: s3,
   // Maximum wait time is required in waiters.
   // Codemod uses 200 seconds as default.
   maxWaitTime: 200
 }, params)

trivikr avatar Nov 20 '23 19:11 trivikr

The performance issues in waiters, if any, may be caused by retry behavior of waiters.

Please create a bug report on aws-sdk-js-v3 repo if you're seeing some concrete differences between v2 and v3 waiters with a minimal repro.

trivikr avatar Nov 20 '23 19:11 trivikr

Could you please observe difference with SDK V2 and V3 when no object exists? I notice it still waits for 200 seconds which was not the case before.

abhirpat avatar Nov 20 '23 20:11 abhirpat

The comment you mentioned would help.

abhirpat avatar Nov 21 '23 18:11 abhirpat

Today, I was able to see that SDK V2 exists immediately when file doesn't exist. Reproduced with "aws-sdk": "^2.1505.0".

const region = 'us-east-1'
const { S3Client, waitUntilObjectExists } = require('@aws-sdk/client-s3');

async function sdkv3(params) {
    const { Bucket, Key } = params;
    const s3 = new S3Client({ region });
    try {
        await waitUntilObjectExists({
            client: s3,
            maxWaitTime: 200
        }, {Bucket, Key})
    } catch (error) {
        console.log("Done with V3")
    }
}


async function sdkv2(params) {
    const { Bucket, Key } = params;
    const AWS = require('aws-sdk');
    AWS.config.region = region;
    const s3 = new AWS.S3();
    try {
        await s3.waitFor('objectExists',{Bucket, Key}).promise()
    } catch (error) {
        console.log('Done with V2')
    }
}

const param = {
    Bucket: 'dev-exportbucket-1nvs7qmdel',
    Key: 'filedoesntexist.json'
  };

sdkv2(param)
// sdkv3(param)

abhirpat avatar Nov 28 '23 18:11 abhirpat