Migrating your code to SDK for JavaScript V3 - AWS SDK for JavaScript

The AWS SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the AWS SDK for JavaScript version 3 (V3).

Migrating your code to SDK for JavaScript V3

AWS SDK for JavaScript version 3 (v3) comes with modernized interfaces for client configurations and utilities, which include credentials, Amazon S3 multipart upload, DynamoDB document client, waiters, and more. You can find what changed in v2 and the v3 equivalents for each change in the migration guide on the AWS SDK for JavaScript GitHub repo.

To take full advantage of SDK for JavaScript v3, we recommend using the codemod scripts described below.

Using codemod

The experimental collection of codemod scripts in aws-sdk-js-codemod helps migrate your existing AWS SDK for JavaScript (v2) application to use v3 APIs. You can run the transform as follows.

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

For example, consider you have the following code, which creates a Amazon DynamoDB client from v2 and calls listTables operation.

// example.ts import AWS from "aws-sdk"; const region = "us-west-2"; const client = new AWS.DynamoDB({ region }); client.listTables({}, (err, data) => { if (err) console.log(err, err.stack); else console.log(data); });

You can run our v2-to-v3 transform on example.ts as follows.

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

The transform will convert the DynamoDB import to v3, create v3 client and call the listTables operation as follows.

// example.ts import { DynamoDB } from "@aws-sdk/client-dynamodb"; const region = "us-west-2"; const client = new DynamoDB({ region }); client.listTables({}, (err, data) => { if (err) console.log(err, err.stack); else console.log(data); });

We’ve implemented transforms for common use cases. If your code doesn’t transform correctly, please create a bug report or feature request with example input code and observed/expected output code. If your specific use case is already reported in an existing issue , show your support by an upvote.