jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
440 stars 60 forks source link

Upgrading to AWS SDK V3 #84

Open ChristopheBougere opened 3 years ago

ChristopheBougere commented 3 years ago

The V3 of the SDK is now generally available (see blog post).

The AWS SDK for JavaScript v3 is a rewrite of v2 with some great new features. As with version 2, it enables you to easily work with Amazon Web Services, but has a modular architecture with a separate package for each service. It also includes many frequently requested features, such as a first-class TypeScript support and a new middleware stack. For more details, visit blog post on general availability of Modular AWS SDK for JavaScript.

It would be great to be able to use it in this package.

In order to keep the v2 compatibility, we could provide the client during initialization instead of requiring it in this package:

import { RDSDataClient } from '@aws-sdk/client-rds-data';
const data = require('data-api-client')({
  client: new RDSDataClient({
    region: process.env.AWS_REGION,
  }),
  secretArn: 'arn:aws:secretsmanager:us-east-1:XXXXXXXXXXXX:secret:mySecret',
  resourceArn: 'arn:aws:rds:us-east-1:XXXXXXXXXXXX:cluster:my-cluster-name',
  database: 'myDatabase' // default database
});

Instead of:

const data = require('data-api-client')({
  secretArn: 'arn:aws:secretsmanager:us-east-1:XXXXXXXXXXXX:secret:mySecret',
  resourceArn: 'arn:aws:rds:us-east-1:XXXXXXXXXXXX:cluster:my-cluster-name',
  database: 'myDatabase' // default database
})
HaaLeo commented 2 years ago

I found this issue because I wanted to inject custom credentials to the data api client which I use via the typeorm-aurora-data-api-driver. In my project I already migrated to the aws-sdk v3. However, it seems that @aws-sdk/credential-providers is somewhat compatible with aws-sdk v2.

The following works for me:

// Import from AWS SDK v3
import { fromIni } from '@aws-sdk/credential-providers';

const { AWS_PROFILE: profile } = process.env;

const options = {
    // ... other options

    // Passed to the AWS SDK V2 RDSDataClient
    serviceConfiguration: {
        credentialProvider: fromIni({ profile }) // this works ✅
    }
}

Maybe that helps somebody with the same issue :). However, I am looking forward when this package is migrated to the AWS SDK v3 ✨.