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]: aws-sdk not changed after converted #753

Open
1 task
mutongwu opened this issue Jan 31, 2024 · 2 comments
Open
1 task

[Feature]: aws-sdk not changed after converted #753

mutongwu opened this issue Jan 31, 2024 · 2 comments
Labels
enhancement New feature or request p2 This is a standard priority issue

Comments

@mutongwu
Copy link

mutongwu commented Jan 31, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

I'd like to update my nodejs version from 16.x to 18.x.
And when I run npx aws-sdk-js-codemod -t v2-to-v3, he statement var AWS = require("aws-sdk"); not changed after converted.

Steps to reproduce

source fie

var AWS = require("aws-sdk");
var endpoint = new AWS.Endpoint(domain);
var request = new AWS.HttpRequest(endpoint, region);

request.method = method;
request.path += index;
request.body = "";
request.headers["host"] = domain;
request.headers["Content-Type"] = "application/json";
request.headers["Content-Length"] = Buffer.byteLength(request.body);

var credentials = new AWS.EnvironmentCredentials("AWS");
var signer = new AWS.Signers.V4(request, "es");
signer.addAuthorization(credentials, new Date());

var client = new AWS.HttpClient();
client.handleRequest(
  request,
  null,
  function (response) {
    console.log(response.statusCode + " " + response.statusMessage);
    var responseBody = "";
    response.on("data", function (chunk) {
      responseBody += chunk;
    });
    response.on("end", function (chunk) {
      success(responseBody);
    });
  },
  function (error) {
    console.log("Error: " + error);
  }
);

output

var AWS = require("aws-sdk");

const { fromEnv } = require("@aws-sdk/credential-providers");

var endpoint = new AWS.Endpoint(domain);
var request = new AWS.HttpRequest(endpoint, region);

request.method = method;
request.path += index;
request.body = "";
request.headers["host"] = domain;
request.headers["Content-Type"] = "application/json";
request.headers["Content-Length"] = Buffer.byteLength(request.body);

var credentials = // JS SDK v3 switched credential providers from classes to functions.
// This is the closest approximation from codemod of what your application needs.
// Reference: https://www.npmjs.com/package/@aws-sdk/credential-providers
fromEnv("AWS");
var signer = new AWS.Signers.V4(request, "es");
signer.addAuthorization(credentials, new Date());

var client = new AWS.HttpClient();
client.handleRequest(
  request,
  null,
  function (response) {
    console.log(response.statusCode + " " + response.statusMessage);
    var responseBody = "";
    response.on("data", function (chunk) {
      responseBody += chunk;
    });
    response.on("end", function (chunk) {
      success(responseBody);
    });
  },
  function (error) {
    console.log("Error: " + error);
  }
);

Observed behavior

$ npx aws-sdk-js-codemod -t v2-to-v3 part.js

╔════════════════════════════════════════════════════════╗
║ Please review the code change thoroughly for required  ║
║ functionality before deploying it to production.       ║
║                                                        ║
║ If the transformation is not complete or is incorrect, ║
║ please report the issue on GitHub.                     ║
╚════════════════════════════════════════════════════════╝

Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
All done.
Results:
0 errors
0 unmodified
0 skipped
1 ok
Time elapsed: 0.244seconds

Expected behavior

require("aws-sdk"); should changed to something from '@aws-sdk/XXX' right?
And AWS.Signers ,AWS.HttpRequest , AWS.Endpoint should changed relevantly

Environment

npx aws-sdk-js-codemod --version
aws-sdk-js-codemod: 1.0.0
- jscodeshift: 0.15.0
- recast: 0.23.4

Additional context

No response

@mutongwu mutongwu added bug Something isn't working triage Triaging bugs labels Jan 31, 2024
@trivikr trivikr added bug Something isn't working enhancement New feature or request triage Triaging bugs p2 This is a standard priority issue and removed triage Triaging bugs bug Something isn't working labels Mar 7, 2024
@trivikr
Copy link
Member

trivikr commented Mar 7, 2024

var endpoint = new AWS.Endpoint(domain);

Feature Request: #694

@trivikr trivikr changed the title [Bug?]: aws-sdk not changed after converted [Feature]: aws-sdk not changed after converted Mar 7, 2024
@trivikr
Copy link
Member

trivikr commented Mar 7, 2024

@mutongwu Where is the signer used in your sample code?

I see only the following lines:

var signer = new AWS.Signers.V4(request, "es");
signer.addAuthorization(credentials, new Date());

The Signers.V4 was removed from public interface aws/aws-sdk-js#1247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants