aws-sdk-js-codemod icon indicating copy to clipboard operation
aws-sdk-js-codemod copied to clipboard

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

Open trivikr opened this issue 7 months ago • 1 comments

Self-service

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

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:

  • https://github.com/ToolJet/ToolJet/blob/bea8d1bd25075503e0873ddc74a0b271be1ce071/plugins/packages/amazonses/lib/index.ts#L80-L87
  • https://github.com/transloadit/uppy/blob/43178f1c4f7369b4275c4e7aa6b7cdc827ff8420/bin/upload-to-cdn.js#L112-L115

trivikr avatar Nov 06 '23 02:11 trivikr