aws / aws-sdk-js-codemod

Codemod scripts to update AWS SDK for JavaScript APIs.
MIT No Attribution
73 stars 10 forks source link

S3 waitFor adding extra delay which changes application behavior #737

Open abhirpat opened 1 year ago

abhirpat commented 1 year ago

Self-service

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

trivikr commented 1 year ago

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 commented 1 year ago

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.

abhirpat commented 1 year ago

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 commented 1 year ago

The comment you mentioned would help.

abhirpat commented 1 year ago

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)