AWS 异常 "Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4" 即使在设置 v4 签名之后
AWS Exception "Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4" even after set the v4 signature
我有以下代码连接到 AWS S3。
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.invoke(ResourceMethodInvocationHandlerFactory.java:81)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.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.run(ServerRuntime.java:326)
......
我在网上搜索了一下,建议将签名设置为版本 4,我已经这样做了。有什么想法吗?
注意我的 aws jdk 已经过时了,因为其他一些库冲突,我无法升级它。
将 AWS SDK 客户端配置设置为 V4 签名
Java:
ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setSignerOverride("AWSS3V4SignerType");
AmazonS3 AmazonS3 =
AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfig)
.build();
节点:
new S3({ signatureVersion: 'v4' })
我有以下代码连接到 AWS S3。
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.invoke(ResourceMethodInvocationHandlerFactory.java:81)
! at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.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.run(ServerRuntime.java:326)
......
我在网上搜索了一下,建议将签名设置为版本 4,我已经这样做了。有什么想法吗?
注意我的 aws jdk 已经过时了,因为其他一些库冲突,我无法升级它。
将 AWS SDK 客户端配置设置为 V4 签名
Java:
ClientConfiguration clientConfig = new ClientConfiguration();
clientConfig.setSignerOverride("AWSS3V4SignerType");
AmazonS3 AmazonS3 =
AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfig)
.build();
节点:
new S3({ signatureVersion: 'v4' })