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]: The v2-to-v3 transform should convert to v3 style of making API calls #497

Open
1 task
trivikr opened this issue Jun 21, 2023 · 6 comments
Open
1 task
Labels
enhancement New feature or request p3 This is a minor priority issue

Comments

@trivikr
Copy link
Member

trivikr commented Jun 21, 2023

Self-service

  • I'd be willing to implement this feature

Template name

v2-to-v3

Input code

import AWS from "aws-sdk";

const region = "us-west-2";
const client = new AWS.DynamoDB({ region });
const response = await client.listTables().promise();

Expected Output

Existing output

import { DynamoDB } from "@aws-sdk/client-dynamodb";

const region = "us-west-2";
const client = new DynamoDB({ region });
const response = await client.listTables();

Recommended output

import { DynamoDB, ListTablesCommand } from "@aws-sdk/client-dynamodb";

const region = "us-west-2";
const client = new DynamoDB({ region });
const response = await client.send(new ListTablesCommand({}));

Additional context

Reference blog post: https://www.10printiamcool.com/updating-to-nodejs-18-and-aws-javascript-sdk-v3-part-1

@trivikr trivikr added the enhancement New feature or request label Jun 21, 2023
@trivikr
Copy link
Member Author

trivikr commented Jun 21, 2023

The codemod defaults to making minimal changes to the customer code to move from v2 to v3.
And the code written in v2 will never use command style of calling APIs, as it was introduced in v3.

@trivikr
Copy link
Member Author

trivikr commented Jun 21, 2023

A better solution could be to write a different transform which converts application code which uses v3 aggregated client to v3 barebones client. That transform can be written separately, but used by default in v2-to-v3.

Example (transform name is assumed to be to-bare-bones-client):

$ cat example.ts
import { DynamoDB } from "@aws-sdk/client-dynamodb";

const region = "us-west-2";
const client = new DynamoDB({ region });
const response = await client.listTables();

$ npx aws-sdk-js-codemod -t to-bare-bones-client example.ts

$ cat example.ts
import { DynamoDB, ListTablesCommand } from "@aws-sdk/client-dynamodb";

const region = "us-west-2";
const client = new DynamoDB({ region });
const response = await client.send(new ListTablesCommand({}));

@trivikr trivikr added the p3 This is a minor priority issue label Jul 25, 2023
@trivikr
Copy link
Member Author

trivikr commented Aug 1, 2023

In #480 (comment), the name api-to-command was recommended for transformer which updates JS SDK v3 code to use commands.

@trivikr
Copy link
Member Author

trivikr commented Aug 15, 2023

We discussed the naming during scrum on 2023-08-15, we decided to stick with to-command-syntax name for the transformer.

@BHunter2889
Copy link

We discussed the naming during scrum on 2023-08-15, we decided to stick with to-command-syntax name for the transformer.

Are there any updates to this? Are there any known community provided transformers out there? We're actively migrating now so this would be a huge win.

@trivikr
Copy link
Member Author

trivikr commented Sep 25, 2024

There are no updates at this point in time. The JS SDK v3 applications can continue to use v2 style of making API calls.
There's no difference in the async behavior between the two styles. The v2 style just calls v3 style internally.

There are no community provided transformers that I know of. This work will likely get prioritized after JS SDK v2 end-of-life in Sept'25 after most JS SDK customers have migrated to v3.

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

No branches or pull requests

2 participants