Skip to content

Commit

Permalink
fix: managed upload resolves config repeatedly (#3700)
Browse files Browse the repository at this point in the history
* fix: managed upload not to resolve config repeatedly

Previously the managed upload creates new S3 clients with the
constructor parameters of the S3 client used to create the managed
upload. That results in that the newly created S3 client needs to
resolve every config, including the credentials over and over
again.

This issue was introduced by #3109 to make sure the internal S3
client inside of managed upload has the same constructor parameters
of the S3 client used to create the managed upload. So that the
logic relies on the constructor parameters like access point
and endpoint discovery works properly.

This change supply the resolved client config to create the
managed upload internal S3 client so configs don't need to be
resolved again, like credentials. Meanwhile, we explicitly set
the constructor parameter to be the same as that of S3 client
used to create the managed upload.

* address feedbacks

Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
  • Loading branch information
AllanZhengYP and trivikr committed Apr 8, 2021
1 parent 34d637e commit 345852e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-ManagedUpload-2bd31158.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "ManagedUpload",
"description": "Use resolved credentials if customer supplies configured S3 Client"
}
8 changes: 7 additions & 1 deletion lib/s3/managed_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,18 @@ AWS.S3.ManagedUpload = AWS.util.inherit({
if (!self.service) {
self.service = new AWS.S3({params: params});
} else {
// Create a new S3 client from the supplied client's constructor.
var service = self.service;
var config = AWS.util.copy(service._originalConfig || {});
var config = AWS.util.copy(service.config);
config.signatureVersion = service.getSignatureVersion();
self.service = new service.constructor.__super__(config);
self.service.config.params =
AWS.util.merge(self.service.config.params || {}, params);
Object.defineProperty(self.service, '_originalConfig', {
get: function() { return service._originalConfig; },
enumerable: false,
configurable: true
});
}
},

Expand Down
17 changes: 16 additions & 1 deletion test/s3/managed_upload.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 345852e

Please sign in to comment.