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

[Bug]: When S3.GetObject is called and Body is processed, the equivalent v3 mixins are not added #789

Open
1 task
trivikr opened this issue Feb 29, 2024 · 1 comment
Labels
bug Something isn't working p2 This is a standard priority issue

Comments

@trivikr
Copy link
Member

trivikr commented Feb 29, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

When S3.GetObject is called and Body is processed, the equivalent v3 mixins are not added

Steps to reproduce

import AWS from "aws-sdk";

const client = new AWS.S3();
const params = {
  Bucket: "my-bucket",
  Key: "my-key",
};
const response = await client.getObject(params).promise();

const data = response.Body;

Observed behavior

The data in the transformed code is a Readable Stream and not a buffer.

import { S3 } from "@aws-sdk/client-s3";

const client = new S3();
const params = {
  Bucket: "my-bucket",
  Key: "my-key",
};
const response = await client.getObject(params);

const data = response.Body;

Expected behavior

The Body needs to be transformed from Readable Stream to Buffer.

import { S3 } from "@aws-sdk/client-s3";

const client = new S3();
const params = {
  Bucket: "my-bucket",
  Key: "my-key",
};
const response = await client.getObject(params);

const data = Buffer.from(await response.Body.transformToByteArray());

Environment

aws-sdk-js-codemod: 1.0.5
- jscodeshift: 0.15.2
- recast: 0.23.4

Additional context

No response

@trivikr trivikr added bug Something isn't working triage Triaging bugs and removed triage Triaging bugs labels Feb 29, 2024
@trivikr
Copy link
Member Author

trivikr commented Feb 29, 2024

Alternative to inform users about this issue:

import { S3 } from "@aws-sdk/client-s3";

const client = new S3();
const params = {
  Bucket: "my-bucket",
  Key: "my-key",
};
// In JS SDK v2, the response body was a Buffer in memory.
// In JS SDK v3, the response body is a Readable Stream which needs to be explicitly consumed.
// Details: https://github.com/aws/aws-sdk-js-v3/blob/main/UPGRADING.md#amazon-s3
const response = await client.getObject(params);

const data = response.Body;

@trivikr trivikr added the p2 This is a standard priority issue label Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

1 participant