aws / aws-sdk-js-codemod

Codemod scripts to update AWS SDK for JavaScript APIs.
MIT No Attribution
69 stars 9 forks source link

[Feature]: Replace AWS.Credentials new instance creation with the credentials object #687

Open trivikr opened 9 months ago

trivikr commented 9 months ago

Self-service

Problem

The new instance creation of AWS.Credentials class is not replaced.

Examples

import AWS from "aws-sdk";

// credentials object as options
const creds = new AWS.Credentials({
  accessKeyId: 'akid',
  secretAccessKey: 'secret',
  sessionToken: 'session',
});
import AWS from "aws-sdk";

// credentials as options
const creds = new AWS.Credentials('akid', 'secret', 'session');

Solution

Replace new instance with Credentials object with a comment that it's the best guess from codemod.

const creds = {
  accessKeyId: 'akid',
  secretAccessKey: 'secret',
  sessionToken: 'session',
};

Alternatives

Wait for JS SDK v3 to provide fromStatic credential provider https://github.com/aws/aws-sdk-js-v3/issues/5452

Additional context

Examples usages in production:

trivikr commented 9 months ago

https://github.com/askrella/whatsapp-chatgpt/blob/3096f7db393a3b5a4e1cd70c64349909b7f9cc8e/src/providers/aws.ts#L10