Codemod scripts to update AWS SDK for JavaScript APIs.

Overview

aws-sdk-js-codemod

This repository contains a collection of codemod scripts for use with JSCodeshift that help update AWS SDK for JavaScript APIs.

The aws-sdk-js-codemod CLI is a lightweight wrapper over jscodeshift. It processes --help, --version and --transform options before passing them downstream.

You can provide names of the custom transforms instead of a local path or url:

 v2-to-v3  Converts AWS SDK for JavaScript APIs in a Javascript/TypeScript
           codebase from version 2 (v2) to version 3 (v3).

Prerequisites

To use aws-sdk-js-codemod, please install Node.js.

Usage

  • Optionally execute dry-run for the transform, and print transformed files on stdout:
    npx aws-sdk-js-codemod --dry --print -t v2-to-v3 PATH...
  • Run transform:
    npx aws-sdk-js-codemod -t v2-to-v3 PATH...

Example

$ cat 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);
});

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

$ cat 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);
});

License

This library is licensed under the MIT-0 License. See the LICENSE file.

Comments
  • [Feature]: The transformer tests are not run in parallel

    [Feature]: The transformer tests are not run in parallel

    Is your feature request related to a problem? Please describe.

    The transformer tests are not run in parallel

    The tests start in parallel, but are run in sync

    Diff:

    -  describe.each(fixtureSubDirs)("%s", (subDir) => {
    +  describe.each(["new-client"])("%s", (subDir) => {
         const subDirPath = join(fixtureDir, subDir);
         it.concurrent.each(getTestFileMetadata(subDirPath))(
           `transforms: %s.%s`,
           async (filePrefix, fileExtension) => {
    +        const startDate = new Date();
    +        console.log(`${filePrefix} start: `, startDate.toTimeString());
    +
             const { input, outputCode } = await getTestMetadata(subDirPath, filePrefix, fileExtension);
             runInlineTest(transformer, null, input, outputCode);
    +
    +        const endDate = new Date();
    +        console.log(`${filePrefix} end: ${endDate.toTimeString()}`);
    +        console.log(`${filePrefix} test run time: ${endDate.getTime() - startDate.getTime()}ms`);
           }
         );
    

    Output:

        global-import start:  14:25:39 GMT-0800 (Pacific Standard Time)
        global-require start:  14:25:39 GMT-0800 (Pacific Standard Time)
        service-import-deep start:  14:25:39 GMT-0800 (Pacific Standard Time)
        service-import start:  14:25:39 GMT-0800 (Pacific Standard Time)
        service-require-deep start:  14:25:39 GMT-0800 (Pacific Standard Time)
    
        service-import end: 14:25:51 GMT-0800 (Pacific Standard Time)
        service-import test run time: 11781ms
    
        service-require start:  14:25:51 GMT-0800 (Pacific Standard Time)
    
        global-require end: 14:26:04 GMT-0800 (Pacific Standard Time)
        global-require test run time: 24973ms
    
        service-require-deep end: 14:26:20 GMT-0800 (Pacific Standard Time)
        service-require-deep test run time: 40440ms
    
        global-import end: 14:26:30 GMT-0800 (Pacific Standard Time)
        global-import test run time: 50777ms
    
        service-import-deep end: 14:26:41 GMT-0800 (Pacific Standard Time)
        service-import-deep test run time: 62212ms
    
        service-require end: 14:27:00 GMT-0800 (Pacific Standard Time)
        service-require test run time: 68779ms
    

    This leads to CI taking time. For example, the test step takes 3m https://github.com/awslabs/aws-sdk-js-codemod/actions/runs/3803141886/jobs/6469293363

    Describe the solution you'd like

    Experiment with Jest code or configuration to run tests in parallel

    Describe alternatives you've considered

    N/A

    Additional Context

    $ yarn dlx -q envinfo --preset jest
    
      System:
        OS: macOS 12.1
        CPU: (8) arm64 Apple M1 Pro
      Binaries:
        Node: 18.12.1 - /private/var/folders/42/54jl1_3x4hz06cf7bc_kzd4h0000gn/T/xfs-6daa84fb/node
        Yarn: 3.3.1 - /private/var/folders/42/54jl1_3x4hz06cf7bc_kzd4h0000gn/T/xfs-6daa84fb/yarn
        npm: 8.19.2 - ~/Library/Caches/fnm_multishells/57062_1672199177403/bin/npm
      npmPackages:
        jest: ^29.3.1 => 29.3.1
    
    opened by trivikr 6
  • Improve the test running time for global-import-new-clients and service-import

    Improve the test running time for global-import-new-clients and service-import

    Is your feature request related to a problem? Please describe.

    During benchmarking, the test global-import-new-clients and service-import took the most time, i.e. 16s. Rest of the tests take ~100ms

    Tested by adding logs:

    // src/transforms/v2-to-v3/transformer.spec.ts
    
    it.each(testFiles)(`transforms correctly using "%s" data`, async (filePrefix, fileExtension) => {
      const testStart = Date.now();
      console.log("test start:", filePrefix, testStart);
    
      // ...
    
      const testEnd = Date.now();
      console.log("test end: ", filePrefix, testEnd);
      console.log("test duration: ", filePrefix, testEnd - testStart);
    }
    

    Output:

    test duration:  global-import-new-clients 15979
    ...
    test duration:  service-import 18148
    

    Describe the solution you'd like

    Check if the issue is with efficiency of source code, which can be improved. If not, identify if tests can be run faster.

    Describe alternatives you've considered

    N/A

    wontfix 
    opened by trivikr 4
  • [Bug]: The v2-to-v3 transform removes top level comment

    [Bug]: The v2-to-v3 transform removes top level comment

    Self-service

    • [ ] I'd be willing to implement a fix

    Describe the bug

    The v2-to-v3 transform removes top level comment

    Template name

    v2-to-v3

    Input code

    // Top level comment
    import AWS from "aws-sdk";
    
    // Create client
    const client = new AWS.DynamoDB({ region: "us-west-2" });
    
    // Make listTables call
    client.listTables({}, (err, data) => {
      if (err) console.log(err, err.stack);
      else console.log(data);
    });
    

    Observed failure

    No failure, but the top level comment is removed

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

    Expected output

    // Top level comment
    import { DynamoDB } from "@aws-sdk/client-dynamodb";
    
    // Create client
    const client = new DynamoDB({ region: "us-west-2" });
    
    // Make listTables call
    client.listTables({}, (err, data) => {
      if (err) console.log(err, err.stack);
      else console.log(data);
    });
    
    ### Environment
    
    ```shell
    aws-sdk-js-codemod: 0.6.4
    
    jscodeshift: 0.14.0
     - babel: 7.20.5
     - babylon: 7.20.5
     - flow: 0.196.2
     - recast: 0.21.5
    

    Additional context

    No response

    bug wontfix 
    opened by trivikr 3
  • chore(workflow): cleanup cached on pull request close

    chore(workflow): cleanup cached on pull request close

    Issue

    Refs: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries

    Description

    Cleans up caches when pull request is closed

    Testing

    Will be done after PR is merged


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 3
  • Deep import search only for available clients

    Deep import search only for available clients

    Issue

    Fixes: https://github.com/awslabs/aws-sdk-js-codemod/issues/263

    Description

    Deep import search only for available clients in getV2ClientNamesRecord

    Testing

    CI


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 2
  • Log time taken by source.find operation in getV2ClientNamesRecord

    Log time taken by source.find operation in getV2ClientNamesRecord

    Issue

    Documenting performance numbers for https://github.com/awslabs/aws-sdk-js-codemod/issues/251

    Description

    Log time taken by source.find operation in getV2ClientNamesRecord


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 2
  • Reduce number of calls to source API in getV2ClientNamesRecord

    Reduce number of calls to source API in getV2ClientNamesRecord

    Issue

    Refs: https://github.com/awslabs/aws-sdk-js-codemod/issues/251#issuecomment-1367689802

    Description

    Reduce number of calls to source API in getV2ClientNamesRecord

    Testing

    CI


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 2
  • [WIP] Use default import/require to minimized identifier conflicts

    [WIP] Use default import/require to minimized identifier conflicts

    Issue

    Attempts to fix https://github.com/awslabs/aws-sdk-js-codemod/issues/239

    Description

    What does this implement/fix? Explain your changes.

    Testing

    How was this change tested?

    Additional context

    Add any other context about the PR here.


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 2
  • [Feature]: Use default imports to minimize identifier conflicts with existing code

    [Feature]: Use default imports to minimize identifier conflicts with existing code

    Self-service

    • [X] I'd be willing to implement this feature

    Input code

    Input:

    import DynamoDB from "aws-sdk/clients/dynamodb";
    
    const ddbClient = new DynamoDB({ region: "us-west-2" });
    const listTablesInput: DynamoDB.ListTablesInput = { Limit: 10 };
    const listTablesOutput: DynamoDB.ListTablesOutput = await ddbClient
      .listTables(listTablesInput)
      .promise();
    

    Existing output:

    import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb";
    
    const ddbClient = new DynamoDB({ region: "us-west-2" });
    const listTablesInput: ListTablesCommandInput = { Limit: 10 };
    const listTablesOutput: ListTablesCommandOutput = await ddbClient
      .listTables(listTablesInput);
    

    Expected Output

    import * as DynamoDB from "@aws-sdk/client-dynamodb";
    
    const ddbClient = new DynamoDB.DynamoDB({ region: "us-west-2" });
    const listTablesInput: DynamoDB.ListTablesCommandInput = { Limit: 10 };
    const listTablesOutput: DynamoDB.ListTablesCommandOutput = await ddbClient.listTables(
      listTablesInput
    );
    

    Additional context

    This solution not only minimizes imports which can conflict with other variables defined in the code, but also adds support for nested type definitions requested in https://github.com/awslabs/aws-sdk-js-codemod/issues/225

    enhancement 
    opened by trivikr 2
  • [Feature]: Do not add newline while updating requires

    [Feature]: Do not add newline while updating requires

    Self-service

    • [ ] I'd be willing to implement this feature

    Input code

    const ACM = require("aws-sdk/clients/acm");
    
    const client = new ACM();
    

    Expected Output

    Expected output

    const { ACM } = require("@aws-sdk/client-acm");
    
    const client = new ACM();
    

    Observed output

    const {
      ACM
    } = require("@aws-sdk/client-acm");
    
    const client = new ACM();
    

    Additional context

    No response

    enhancement wontfix 
    opened by trivikr 2
  • fix(workflow): compute branch name from pull_request number

    fix(workflow): compute branch name from pull_request number

    Issue

    Follow-up to https://github.com/awslabs/aws-sdk-js-codemod/pull/174

    Description

    Computer branch name from pull_request number

    Testing

    Will be done after PR is merged

    Additional context

    Docs: https://docs.github.com/developers/webhooks-and-events/webhooks/webhook-events-and-payloads?actionType=closed#pull_request


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 2
  • Add test new-client/global-import-equals

    Add test new-client/global-import-equals

    Issue

    Fixes https://github.com/awslabs/aws-sdk-js-codemod/issues/243

    Description

    What does this implement/fix? Explain your changes.

    Testing

    How was this change tested?

    Additional context

    Add any other context about the PR here.


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 2
  • Test case for nested types which are different between v2 and v3

    Test case for nested types which are different between v2 and v3

    Issue

    Refs: https://github.com/awslabs/aws-sdk-js-codemod/issues/225

    Description

    What does this implement/fix? Explain your changes.

    Testing

    How was this change tested?

    Additional context

    Add any other context about the PR here.


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 1
  • [Feature]: Support ImportEqualsDeclaration

    [Feature]: Support ImportEqualsDeclaration

    Self-service

    • [X] I'd be willing to implement this feature

    Input code

    import AWS = require("aws-sdk");
    
    const client = new AWS.DynamoDB({ region: "us-west-2" });
    

    Expected Output

    import { DynamoDB } = require("@aws-sdk/client-dynamodb");
    
    const client = new DynamoDB({ region: "us-west-2" });
    

    Additional context

    This missing feature was noticed in https://github.com/awslabs/aws-sdk-js-codemod/issues/242

    enhancement 
    opened by trivikr 1
  • Add initial support for DynamoDB DocumentClient transformation

    Add initial support for DynamoDB DocumentClient transformation

    Issue

    Fixes: https://github.com/awslabs/aws-sdk-js-codemod/issues/51

    Description

    Add initial support for DynamoDB DocumentClient transformation

    Testing

    CI


    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by trivikr 1
  • [Feature]: Migrating nested type definitions from v2 to v3

    [Feature]: Migrating nested type definitions from v2 to v3

    Self-service

    • [ ] I'd be willing to implement this feature

    Test Comand

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

    Input code

    import { S3 } from "aws-sdk";
    const testTags: S3.Tag[] = [{ Key: "abc", Value: "value" }];
    

    Current Output

    Results:
    0 errors
    1 unmodified
    0 skipped
    0 ok
    

    Expected Output

    import { Tag } from "@aws-sdk/client-s3";
    const testTags: Tag[] = [{ Key: "abc", Value: "value" }];
    

    Additional context

    Would it be possible to migrate the import of Typescript type definitions from v2 to v3? My project has a global store that uses the AWS SDK types to store objects and tags. During migration, it'll be great to also have those types updated to their v3 references.

    enhancement 
    opened by eddwon 2
  • [Bug]: npx does not use the latest version of the codemod

    [Bug]: npx does not use the latest version of the codemod

    Describe the bug

    npx does not use the latest version of codemod

    Steps to reproduce

    To reproduce, you need to have an older version of aws-sdk-js-codemod installed

    $ npm view aws-sdk-js-codemod version 
    0.6.3
    
    $ npx aws-sdk-js-codemod --version
    aws-sdk-js-codemod: 0.6.1
    ...
    

    Run the following commands:

    $ npx aws-sdk-js-codemod@latest --version
    
    $ npx aws-sdk-js-codemod --version
    

    Observed behavior

    When latest is explicitly passed, it uses the latest version. But it does not override the previously installed version

    $ npx aws-sdk-js-codemod@latest --version
    Need to install the following packages:
      [email protected]
    Ok to proceed? (y) y
    aws-sdk-js-codemod: 0.6.3
    ...
    
    $ npx aws-sdk-js-codemod --version 
    aws-sdk-js-codemod: 0.6.1
    ...
    

    Expected behavior

    Default documentation should update how to use the latest version.

    The current usage recommends npx aws-sdk-js-codemod which will use the catched version: https://github.com/awslabs/aws-sdk-js-codemod#usage

    opened by trivikr 2
Releases(v0.8.0)
Owner
Amazon Web Services - Labs
AWS Labs
Amazon Web Services - Labs
Under the Sea is an official AWS workshop delivered by AWS SAs and AWS Partners to help customers and partners to learn about AIOps with serverless architectures on AWS.

Under the Sea - AIOps with Serverless Workshop Under the Sea is an exciting MMORPG developed by the famous entrepreneur behind Wild Rydes, the most po

AWS Samples 4 Nov 16, 2022
My terrible attempt at a promposal. Update: She said yes LMFAO Update Update: I got friendzoned right after 😭

TypeScript Next.js example This is a really simple project that shows the usage of Next.js with TypeScript. Deploy your own Deploy the example using V

John Li (Tet) 7 Oct 27, 2022
Learn Web 2.0 and Web 3.0 Development using Next.js, Typescript, AWS CDK, AWS Serverless, Ethereum and AWS Aurora Serverless

Learn Web 2.0 Cloud and Web 3.0 Development in Baby Steps In this course repo we will learn Web 2.0 cloud development using the latest state of the ar

Panacloud Multi-Cloud Internet-Scale Modern Global Apps 89 Jan 3, 2023
MerLoc is a live AWS Lambda function development and debugging tool. MerLoc allows you to run AWS Lambda functions on your local while they are still part of a flow in the AWS cloud remote.

MerLoc MerLoc is a live AWS Lambda function development and debugging tool. MerLoc allows you to run AWS Lambda functions on your local while they are

Thundra 165 Dec 21, 2022
AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs UDEMY COURSE WITH DISCOUNTED - Step by Step Development of this Repository -> https://www

awsrun 35 Dec 17, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Powershell scripts and Update script for Powershell configs and oh-my-posh themes

windows-powershell-autoconfig What is it? It is a NodeJS Project which updates your powershell and oh-my-posh scripts. Why should I use it? It is very

Skender Gashi 6 Dec 28, 2022
The iofod SDK provides developers with the ability to interact with the main iofod interface within the Web worker, enabling rapid development of iofod extensions through the SDK.

iofod-sdk English | 简体中文 The iofod SDK provides developers with the ability to interact with the main iofod interface within the Web worker, enabling

iofod, Inc. 47 Oct 17, 2022
Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's `move-ts`.

Movehat Movehat is a TypeScript SDK for Move on Sui built on top of Sui's TypeScript SDK and our fork of Ian Macalinao's move-ts. Movehat aspires to b

Pentagon 10 Sep 30, 2022
A serverless AWS expense tracker API. AWS Lambda functions, API gateway, and Dynamodb are among the ingredients.

AWS-Serverless-API A serverless AWS expense tracker API. AWS Lambda functions API gateway Dynamodb Endpoints Create a new expense: Method: POST Body f

Ondiek Elijah Ochieng 1 Jul 16, 2022
Everynode allows you to run any version of Node.js in AWS Lambda, in any commercial AWS region

Run Any Node.js Version in AWS Lambda Everynode allows you to run any version of Node.js in AWS Lambda, in any commercial AWS region. We add support f

Fusebit 116 Dec 15, 2022
Deploy an Architect project from GitHub Actions with keys gathered from aws-actions/configure-aws-credentials

Deploy an Architect project from GitHub Actions with keys gathered from a specific AWS IAM Role federated by an IAM OIDCProvider. CloudFormation to cr

Taylor Beseda 4 Apr 6, 2022
A monorepo that uses the AWS Cloud Development Kit to deploy and configure nanomdm on AWS lambda.

NanoMDM on AWS This repo builds and configures a nanomdm server to run on AWS lambda. It uses the Cloud Development Kit and tries to follow best pract

Stevie Clifton 4 May 26, 2022
a stack-separated way to bringing together common AWS services useful in a fullstack application that uses AWS Amplify libraries

Fullstack CDK Helpers This project helps developers create common AWS services that are useful in creating fullstack applications. Backend services ar

Focus Otter 14 Nov 26, 2022
Lumos is an AWS Lambda visualizer and open source alternative to AWS CloudWatch.

Lumos Lambda Metrics Visualizer Table of Contents About Lumos Techologies Used Getting Started Key Lambda Metrics How to Contribute License Contributo

OSLabs Beta 36 Nov 5, 2022
An Amazon Kendra REST API CDK example with an API Gateway, including authentication with AWS Cognito and AWS X-Ray Tracing

Amazon Kendra Web Service CDK Sample Amazon Kendra has a robust JSON API for use with the AWS SDK (software development kit), but does not expose endp

AWS Samples 8 Nov 28, 2022