Skip to content

Commit ea0c0c7

Browse files
authored
fix: create clients only if necessary (#187)
1 parent 576ea66 commit ea0c0c7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/java/software/amazon/encryption/s3/S3AsyncEncryptionClient.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void close() {
251251
// This is very similar to the S3EncryptionClient builder
252252
// Make sure to keep both clients in mind when adding new builder options
253253
public static class Builder {
254-
private S3AsyncClient _wrappedClient = S3AsyncClient.builder().build();
254+
private S3AsyncClient _wrappedClient;
255255
private CryptographicMaterialsManager _cryptoMaterialsManager;
256256
private Keyring _keyring;
257257
private SecretKey _aesKey;
@@ -507,6 +507,10 @@ public S3AsyncEncryptionClient build() {
507507
_bufferSize = DEFAULT_BUFFER_SIZE_BYTES;
508508
}
509509

510+
if (_wrappedClient == null) {
511+
_wrappedClient = S3AsyncClient.create();
512+
}
513+
510514
if (_keyring == null) {
511515
if (_aesKey != null) {
512516
_keyring = AesKeyring.builder()

src/main/java/software/amazon/encryption/s3/materials/KmsKeyring.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ protected Map<String, DecryptDataKeyStrategy> decryptDataKeyStrategies() {
230230
}
231231

232232
public static class Builder extends S3Keyring.Builder<KmsKeyring, Builder> {
233-
private KmsClient _kmsClient = KmsClient.builder().build();
233+
private KmsClient _kmsClient;
234234
private String _wrappingKeyId;
235235

236236
private Builder() {
@@ -258,6 +258,10 @@ public Builder wrappingKeyId(String wrappingKeyId) {
258258
}
259259

260260
public KmsKeyring build() {
261+
if (_kmsClient == null) {
262+
_kmsClient = KmsClient.create();
263+
}
264+
261265
return new KmsKeyring(this);
262266
}
263267
}

0 commit comments

Comments
 (0)