Skip to content

Commit d208a23

Browse files
authored
Merge pull request #138 from saravanak/aws-sdk-v3-upgrade
Fixes #137 AWS sdk v3 upgrade
2 parents 21151b6 + 7a8719b commit d208a23

File tree

6 files changed

+1593
-126
lines changed

6 files changed

+1593
-126
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
/libpeerconnection.log
1616
npm-debug.log
1717
testem.log
18+
19+
.tool-versions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ A flag to specify whether the revision should be overwritten if it already exist
140140

141141
The underlying S3 library used to upload the files to S3. This allows the user to use the default upload client provided by this plugin but switch out the underlying library that is used to actually send the files.
142142

143-
The client specified MUST implement functions called `getObject` and `putObject`.
143+
The client specified MUST implement functions called `getObject` and `putObject`. See [Using V2 API] (https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/welcome.html#using_v2_commands).
144144

145-
*Default:* the default S3 library is `aws-sdk`
145+
*Default:* the default S3 library is `@aws-sdk/s3-client` (AWS JS SDK v3). Please use this addon version < 3.0.0 if you want to use AWS JS SDK 2.0
146146

147147
### endpoint
148148

@@ -334,4 +334,4 @@ If you'd like to be able to preview a deployed revision before activation, you'l
334334
[4]: https://github.com/ember-cli-deploy/ember-cli-deploy-build "ember-cli-deploy-build"
335335
[5]: https://github.com/ember-cli/ember-cli-deploy "ember-cli-deploy"
336336
[6]: https://github.com/ember-cli-deploy/ember-cli-deploy-revision-data "ember-cli-deploy-revision-data"
337-
[7]: https://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Setting_AWS_Credentials "Setting AWS Credentials"
337+
[7]: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-node-credentials-shared.html "Setting AWS Credentials"

lib/s3.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
var AWS = require('aws-sdk');
3+
var { fromIni } = require('@aws-sdk/credential-providers');
4+
var { S3 } = require('@aws-sdk/client-s3');
45
var CoreObject = require('core-object');
56
var RSVP = require('rsvp');
67
var fs = require('fs');
@@ -31,20 +32,31 @@ module.exports = CoreObject.extend({
3132
var config = plugin.pluginConfig;
3233
var profile = plugin.readConfig('profile');
3334
var endpoint = plugin.readConfig('endpoint');
35+
var credentials;
3436

3537
this._plugin = plugin;
3638

37-
if (profile && !this._plugin.readConfig('s3Client')) {
38-
this._plugin.log('Using AWS profile from config', { verbose: true });
39-
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: profile });
39+
var providedS3Client = plugin.readConfig("s3Client");
40+
41+
42+
if (profile && !providedS3Client) {
43+
this._plugin.log("Using AWS profile from config", { verbose: true });
44+
credentials = fromIni({ profile: profile });
4045
}
4146

4247
if (endpoint) {
43-
this._plugin.log('Using endpoint from config', { verbose: true });
44-
AWS.config.endpoint = new AWS.Endpoint(endpoint);
48+
this._plugin.log('Using endpoint from config', { verbose: true });
4549
}
4650

47-
this._client = plugin.readConfig('s3Client') || new AWS.S3(config);
51+
this._client = providedS3Client || new S3(config);
52+
53+
if (endpoint) {
54+
this._client.config.endpoint = endpoint;
55+
}
56+
if (credentials) {
57+
this._client.config.credentials = credentials;
58+
}
59+
4860
},
4961

5062
upload: function(options) {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cli-deploy-s3-index",
3-
"version": "3.0.0",
3+
"version": "4.0.0-0",
44
"description": "Ember CLI Deploy plugin to deploy ember-cli's bootstrap index file to S3.",
55
"keywords": [
66
"ember-addon",
@@ -18,7 +18,8 @@
1818
"test": "node tests/runner.js && ./node_modules/.bin/eslint index.js lib/* tests/**/*.js"
1919
},
2020
"dependencies": {
21-
"aws-sdk": "^2.667.0",
21+
"@aws-sdk/client-s3": "^3.385.0",
22+
"@aws-sdk/credential-providers": "^3.391.0",
2223
"core-object": "^3.0.0",
2324
"ember-cli-deploy-plugin": "^0.2.9",
2425
"mime-types": "^2.1.27",

tests/unit/lib/s3-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ describe('s3', function() {
3535
copyObject: function(params, cb) {
3636
copyParams = params;
3737
cb();
38-
}
38+
},
39+
config: {}
3940
};
4041
mockUi = {
4142
messages: [],
@@ -222,7 +223,7 @@ describe('s3', function() {
222223
var promise = subject.upload(options);
223224
return assert.isFulfilled(promise)
224225
.then(function() {
225-
assert.equal(require('aws-sdk').config.endpoint.host, endpoint, 'Endpoint in SDK is correct');
226+
assert.equal(s3Client.config.endpoint, endpoint, 'Endpoint in SDK is correct');
226227
assert.equal(mockUi.messages[0], '- Using endpoint from config', 'Prefix is included in log output');
227228
});
228229
});

0 commit comments

Comments
 (0)