【问题标题】:AmazonS3EncryptionClientV2 - Unable to find a region via the region provider chainAmazonS3EncryptionClientV2 - 无法通过区域提供商链找到区域
【发布时间】:2022-01-04 13:36:27
【问题描述】:

我必须从 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


    【解决方案1】:

    试试这个

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

    【讨论】:

    【解决方案2】:

    遇到同样的问题并通过创建配置文件解决了它

    ~/.aws/config

    [默认]

    region=us-east-2

    【讨论】:

      猜你喜欢
      • 2017-10-24
      • 1970-01-01
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 2020-09-03
      • 2018-09-20
      • 2015-07-27
      • 2020-09-13
      相关资源
      最近更新 更多