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

TypeError for getBucketLifecycleConfiguration() in aws-sdk/client-s3 #3585

Closed
3 of 4 tasks
ardenercelik opened this issue Apr 11, 2022 · 3 comments · Fixed by #3623
Closed
3 of 4 tasks

TypeError for getBucketLifecycleConfiguration() in aws-sdk/client-s3 #3585

ardenercelik opened this issue Apr 11, 2022 · 3 comments · Fixed by #3623
Assignees
Labels
bug This issue is a bug. needs-review This issue/pr needs review from an internal developer.

Comments

@ardenercelik
Copy link

ardenercelik commented Apr 11, 2022

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
Although I am using the getBucketLifecycleConfiguration correctly, I am getting a internal TypeError in aws-sdk/client-s3. The operation is working as expected when using boto3 or aws cli tool like below

$ aws s3api get-bucket-lifecycle-configuration --bucket name-of-our-s3-bucket

Is the issue in the browser/Node.js?
Node.js

If on Node.js, are you running this on AWS Lambda?
No

Details of the browser/Node.js version
v16.13.2

SDK version number
"@aws-sdk/client-s3": "^3.67.0"

To Reproduce (observed behavior)
I saw this behaviour in our 3 s3 buckets total

const s3 =  new S3({ region: 'our-s3-region' })
const lifecycle = await s3.getBucketLifecycleConfiguration({Bucket: 'name-of-our-s3-bucket'});
//throws
TypeError: Expected object, got string
    at expectObject (node_modules/@aws-sdk/smithy-client/dist-cjs/parse-utils.js:97:11)
    at expectUnion (node_modules/@aws-sdk/smithy-client/dist-cjs/parse-utils.js:114:47)
    at deserializeAws_restXmlLifecycleRule (node_modules/@aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js:11624:101)
    atnode_modules/@aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js:11708:16
    at Array.map (<anonymous>)
    at deserializeAws_restXmlLifecycleRules (node_modules/@aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js:11704:10)
    at deserializeAws_restXmlGetBucketLifecycleConfigurationCommand (node_modules/@aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js:5571:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
    at async node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:11:20 {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

Expected behavior
To dump Lifecycle configuration for the specified bucket.

@ardenercelik ardenercelik added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 11, 2022
@trivikr trivikr transferred this issue from aws/aws-sdk-js May 2, 2022
@yenfryherrerafeliz yenfryherrerafeliz self-assigned this May 3, 2022
@yenfryherrerafeliz yenfryherrerafeliz removed the needs-triage This issue or PR still needs to be triaged. label May 3, 2022
@yenfryherrerafeliz
Copy link
Contributor

Hi @ardenercelik, thank you for reaching out. I was able to reproduce the reported behavior and the reason why this happens is because one of the internal validation of the SDK is expecting that one of the fields from the response, either, or not to be present or that the value be an object, but an empty string is being received instead. Please see below:

Response:
{
  ID: 'autodeletion',
  Filter: '', // This is the field that causes the problem
  Status: 'Enabled',
  Expiration: { ExpiredObjectDeleteMarker: 'true' },
  NoncurrentVersionExpiration: { NoncurrentDays: '1', NewerNoncurrentVersions: '1' },
  AbortIncompleteMultipartUpload: { DaysAfterInitiation: '1' }
}
Validation:
if (output["Filter"] !== undefined) {
    // Here when we pass the field Filter the function generates an exception if the field value is not an object
    contents.Filter = deserializeAws_restXmlLifecycleRuleFilter(__expectUnion(output["Filter"]), context);
}
Possible fix:
// With the following conditions we make sure that "Filter" is defined and is not an empty string
if (output["Filter"] !== undefined && output["Filter"] !== '') {
    contents.Filter = deserializeAws_restXmlLifecycleRuleFilter(__expectUnion(output["Filter"]), context);
}

The validation is done in the following ts file:

  • SDKPATH/clients/client-s3/src/protocols/Aws_restXml.ts, line 13456.

I will mark this issue to review so one of our developers take a look to it.

Thank you!

@yenfryherrerafeliz yenfryherrerafeliz added the needs-review This issue/pr needs review from an internal developer. label May 3, 2022
@yenfryherrerafeliz yenfryherrerafeliz removed their assignment May 3, 2022
@AllanZhengYP AllanZhengYP removed the needs-review This issue/pr needs review from an internal developer. label May 10, 2022
@yenfryherrerafeliz
Copy link
Contributor

@AllanZhengYP here is the body:

Body:  {
  xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/',
  Rule: {
    ID: 'autodeletion',
    Filter: '',
    Status: 'Enabled',
    Expiration: { ExpiredObjectDeleteMarker: 'true' },
    NoncurrentVersionExpiration: { NoncurrentDays: '1', NewerNoncurrentVersions: '1' },
    AbortIncompleteMultipartUpload: { DaysAfterInitiation: '1' }
  }
}

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. needs-review This issue/pr needs review from an internal developer.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants