Replace AWS SDK v2 clients with v3 clients

Proprietary

Ports the v2-to-v3 transform of aws-sdk-js-codemod: each v2 client (AWS.S3, require('aws-sdk/clients/s3'), import {S3} from 'aws-sdk', ...) becomes the v3 client class of the same shape from its @aws-sdk/client-* package, so calls keep their form: .promise() is dropped, and a callback-only call gets {} for its input. AWSError as a type becomes the service exception of the file's one client (S3ServiceException), or ServiceException from @smithy/smithy-client in a file with none or several, and an error's fields move to their v3 names (code → name, statusCode → $metadata?.httpStatusCode, requestId → $metadata?.requestId, retryable → $retryable, ...) where it is typed AWSError or handles a client call's failure. Client options move to their v3 names (credentials under credentials, maxRetries to maxAttempts, s3ForcePathStyle to forcePathStyle, ...). S3 upload(...).promise() becomes Upload from @aws-sdk/lib-storage, getSignedUrl and getSignedUrlPromise become getSignedUrl from @aws-sdk/s3-request-presigner, createPresignedPost becomes createPresignedPost from @aws-sdk/s3-presigned-post with Fields.key as its Key, DynamoDB.DocumentClient becomes DynamoDBDocument from @aws-sdk/lib-dynamodb (removing undefined values as v2 did), and v2 types (AWS.S3.GetObjectRequest) become v3 types (GetObjectCommandInput). A file is migrated whole or not at all: one that uses anything without a mechanical v3 equivalent is left unchanged, and FindAwsSdkV2ManualMigrations says why. So is a file that exports a client while another file of its lock group calls a v2-only API on a value from elsewhere. A lock group (a workspace root with its members, or a standalone package.json) is migrated whole or not at all: where one of its sources stays on v2, none of them is changed, and so where the oldest Node.js it declares (engines.node, .nvmrc, .node-version, a Lambda runtime) runs no v3 release.

org.openrewrite.node.migrate.aws-sdk-v3.replace-aws-sdk-v2-clients

Optional

The version range the migration declares for each added @aws-sdk/* package. A lock group whose oldest declared Node.js can't run the newest release it admits is left on v2.

mod run . --recipe=org.openrewrite.node.migrate.aws-sdk-v3.replace-aws-sdk-v2-clients

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.