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

[Feature]: transform new S3({ accessKeyId }) #454

Closed
1 task
saschanaz opened this issue Mar 2, 2023 · 6 comments
Closed
1 task

[Feature]: transform new S3({ accessKeyId }) #454

saschanaz opened this issue Mar 2, 2023 · 6 comments
Labels
enhancement New feature or request p2 This is a standard priority issue

Comments

@saschanaz
Copy link

saschanaz commented Mar 2, 2023

Self-service

  • I'd be willing to implement this feature

Template name

v2-to-v3

Input code

import { S3 } from 'aws-sdk';

const params = {
	Bucket: 'example',
	Key: 'key',
	Body: Buffer.from(''),
	ContentType: 'application/json',
	CacheControl: 'max-age=31536000, immutable',
} as S3.PutObjectRequest;

const s3 = new S3({
	endpoint: 'example',
	accessKeyId: 'example',
	secretAccessKey: 'example',
	region: 'example',
	sslEnabled: true,
	s3ForcePathStyle: 'example',
});

const upload = s3.upload(params, {
	partSize: s3.endpoint.hostname === 'storage.googleapis.com' ? 500 * 1024 * 1024 : 8 * 1024 * 1024,
});

await upload.promise();

Expected Output

I don't know what's expected.

Additional context

Actual result:

import { Upload } from "@aws-sdk/lib-storage";
import AWS_S3, { S3 } from "@aws-sdk/client-s3";

const params = {
        Bucket: 'example',
        Key: 'key',
        Body: Buffer.from(''),
        ContentType: 'application/json',
        CacheControl: 'max-age=31536000, immutable',
} as AWS_S3.PutObjectCommandInput;

const s3 = new S3({
        endpoint: 'example',
        accessKeyId: 'example',
        secretAccessKey: 'example',
        region: 'example',
        sslEnabled: true,
        s3ForcePathStyle: 'example',
});

const upload = new Upload({
    client: s3,
    params,
    partSize: s3.endpoint.hostname === 'storage.googleapis.com' ? 500 * 1024 * 1024 : 8 * 1024 * 1024
});

await upload.promise();

But accessKeyId doesn't seem to be supported by the S3 constructor in v3, and thus probably should be converted to something else.

@lclarkg18
Copy link

lclarkg18 commented Mar 3, 2023

I'm also having the same issue

@lclarkg18
Copy link

lclarkg18 commented Mar 3, 2023

I'm also getting TS2339: Property 'upload' does not exist on type 'S3'. here:

      return await this.s3
        .upload({
          Bucket: this.bucket,
          Key: key,
          Body: file.buffer,
          ContentType: file.mimetype,
        })
        .promise();

and TS2339: Property 'promise' does not exist on type 'Promise ' here:

  async deleteFile(key) {
    await this.s3
      .deleteObject({
        Bucket: this.bucket,
        Key: key,
      })
      .promise();
  }

I'm not a big AWS user so this may be partly because of my own poor code. I will be sticking to v2 for now because it's just causing too many errors with no information about how to debug

@saschanaz
Copy link
Author

I guess that's a separate issue that the codemod can't track this.s3 properly, if you are talking about the codemod result. Maybe file a new issue?

@trivikr trivikr added the p2 This is a standard priority issue label Mar 6, 2023
@bodelia
Copy link

bodelia commented May 10, 2023

I ran into the same issue.
found a solution here : https://stackoverflow.com/questions/68264237/how-to-set-credentials-in-aws-sdk-v3-javascript

Simply put

import { S3 } from 'aws-sdk';
new S3({
	accessKeyId: 'example',
	secretAccessKey: 'example'
});

Should be transformed into

import { S3 } from 'aws-sdk/client-s3';
new S3({
	credentials: {
		accessKeyId: 'example',
		secretAccessKey: 'example'
	}
});

@trivikr
Copy link
Member

trivikr commented Nov 13, 2023

Credentials transformation was added in #661

Open feature request for tracking this.s3 is at #686

@trivikr trivikr closed this as completed Nov 13, 2023
Copy link
Contributor

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 Nov 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

4 participants