Skip to content

Commit a2ab921

Browse files
authored
Merge pull request #23 from txase/feature/aws-sdk-v3
Feat: Upgrade to AWS SDK v3
2 parents 0770c1b + c71ba83 commit a2ab921

File tree

6 files changed

+6947
-4172
lines changed

6 files changed

+6947
-4172
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ knex.transaction(async trx => {
7575
```
7676
7777
## Breaking Changes
78+
### Version 2 to 3
79+
Version 3 uses version 3 of the AWS SDK. This SDK is included automatically in the `nodejs18.x` AWS Lambda runtime and above.
80+
81+
`@aws-sdk/client-rds-data` and `@smithy/node-http-handler` are only included as dev dependencies. You will need to make sure those two packages are available in some form in your project.
82+
7883
### Version 1 to 2
7984
Version 1 depended on aws-sdk, which at the time of the change was 71 MB in size. This package may be used in contexts where package size is important and the SDK may already be available, such as AWS Lambda Functions.
8085

index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// AWS Aurora MySQL Data API Client
22
// -------
3+
const { ExecuteStatementCommand, RDSDataClient } = require('@aws-sdk/client-rds-data');
4+
const { NodeHttpHandler } = require('@smithy/node-http-handler');
35
const map = require('lodash.map');
46
const Client_MySQL = require('knex/lib/dialects/mysql'); // eslint-disable-line camelcase
57
const Transaction = require('./transaction');
@@ -61,23 +63,27 @@ class Client_AuroraDataMySQL extends Client_MySQL { // eslint-disable-line camel
6163
_driver () {
6264
let RDSDataService;
6365
try {
64-
RDSDataService = require('aws-sdk/clients/rdsdataservice');
66+
RDSDataService = RDSDataClient;
6567
} catch (err) { /* istanbul ignore next */
6668
throw new Error(`Failed to load aws-sdk rdsdataservice client, did you forget to install it as a dependency? (${err.message})`);
6769
}
6870

69-
const https = this.config.connection.sdkConfig && String(this.config.connection.sdkConfig.endpoint).startsWith('http:')
71+
const isHttp = this.config.connection.sdkConfig && String(this.config.connection.sdkConfig.endpoint).startsWith('http:');
72+
73+
const https = isHttp
7074
? require('http')
7175
: require('https');
7276

7377
const agent = new https.Agent({
7478
keepAlive: true
7579
});
7680

81+
const requestHandler = new NodeHttpHandler({
82+
[isHttp ? 'httpAgent' : 'httpsAgent']: agent
83+
});
84+
7785
const config = {
78-
httpOptions: {
79-
agent
80-
},
86+
requestHandler,
8187
...(this.config.connection.sdkConfig || {})
8288
};
8389

@@ -221,9 +227,9 @@ class Client_AuroraDataMySQL extends Client_MySQL { // eslint-disable-line camel
221227
params.transactionId = connection.transactions[connection.__knexTxId];
222228
}
223229

224-
obj.data = await connection.client
225-
.executeStatement(params)
226-
.promise();
230+
const command = new ExecuteStatementCommand(params);
231+
232+
obj.data = await connection.client.send(command);
227233

228234
return obj;
229235
}

0 commit comments

Comments
 (0)