首页 > 解决方案 > 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 这样的另一个客户端时,一切正常。

标签: amazon-s3

解决方案


尝试这个

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()

推荐阅读