amazon-s3 - AmazonS3EncryptionClientV2 - 无法通过区域提供商链找到区域
问题描述
我必须从 AmazonS3EncryptionClient 迁移到 AmazonS3EncryptionClientV2,因此我遵循以下说明:https ://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/s3-encryption-migration.html ,但我'我总是遇到同样的错误,即使区域已设置:“无法通过区域提供者链找到区域。必须在构建器或设置环境中提供显式区域以提供区域。”
AmazonS3 s3Encryption = AmazonS3EncryptionClientV2.encryptionBuilder()
.withRegion(Regions.EU_CENTRAL_1)
.withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(AWS_S3_KEY, AWS_S3_SECRET)))
.withCryptoConfiguration(new CryptoConfigurationV2()
// The following setting allows the client to read V1 encrypted objects
.withCryptoMode(CryptoMode.AuthenticatedEncryption)
.withCryptoProvider(new BouncyCastleProvider()))
.withEncryptionMaterialsProvider(new StaticEncryptionMaterialsProvider(
new EncryptionMaterials(createKeyPair(AWS_S3_PRIVATE_KEY,
AWS_S3_PUBLIC_KEY))))
.build();
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.908</version>
</dependency>
有人有想法吗?因为当我使用像 AmazonS3ClientBuilder 这样的另一个客户端时,一切正常。
解决方案
尝试这个
val kmsClient:AWSKMS = AWSKMSClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
val s3Client:AmazonS3EncryptionV2 = AmazonS3EncryptionClientV2Builder.standard()
.withKmsClient(kmsClient)
.withRegion(Regions.US_EAST_1)
.withCryptoConfiguration(new CryptoConfigurationV2().withCryptoMode((CryptoMode.StrictAuthenticatedEncryption)))
.withEncryptionMaterialsProvider(materialProvider)
.build()
推荐阅读
- haskell - 我的 Haskell 代码出现一个非常普遍的错误:解析错误(可能不正确的缩进或不匹配的括号)
- c - 运行代码时如何查看我在 Netbeans 中编写的内容?
- c# - 如何使用 LINQ 和 C# 从继承的类中选择所有列
- raspberry-pi - 如何使用端口在 PC 上打开 Rasperry IP
- javascript - javascript幻灯片的图像数组没有出现
- javascript - 条件表达式中的 JavaScript 标记类型 if
- java - 未使用 FirebaseMessaging 接收前台通知但在后台工作
- reactjs - 如何在组件树外的实用程序函数中使用 react-i18next?
- f# - 简单的添加函数来处理整数和浮点数
- c# - 如何禁用其他数据网格上的格式化等于列?