aws异常“使用aws kms托管密钥指定服务器端加密的请求需要aws签名版本4”,即使在设置v4签名之后也是如此

wribegjk  于 2021-06-26  发布在  Java
关注(0)|答案(1)|浏览(383)

我有下面的代码连接到awss3。

System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "true");

    try {
        s3Client = new AmazonS3Client(new BasicAWSCredentials("myAccessKey", "mySecretKey"), new ClientConfiguration());
        ......
        s3Client.putObject(...);
        ......
    } catch (Exception e) {
        System.out.println(e.toString());
    }

但是,我有一个错误

com.amazonaws.services.s3.model.AmazonS3Exception: Status Code: 400, AWS Service: Amazon S3, AWS Request ID: 9CA32042ABE3635A, AWS Error Code: InvalidArgument, AWS Error Message: Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4.
! at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:798)
! at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:421)
! at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:232)
! at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3528)
! at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1393)
! at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1249)
! at com.aktana.dse2020.data.service.S3Service.put(S3Service.java:107)
! at com.aktana.api.resource.DSEConfiguratorResource.getConfigTransferExport(DSEConfiguratorResource.java:1278)
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at java.lang.reflect.Method.invoke(Method.java:498)
! at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
! at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
! at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
! at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
......

我在网上搜索了一下,建议将签名设置为第4版,我已经这么做了。有什么想法吗?
注意我的awsjdk是相当过时的,因为我不能升级它由于一些其他libs冲突。

doinxwow

doinxwow1#

将aws sdk客户端配置设置为v4签名
java 语:

ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setSignerOverride("AWSS3V4SignerType");
AmazonS3 AmazonS3 = 
 AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfig)
            .build();

节点:

new S3({ signatureVersion: 'v4' })

相关问题