I have below code to connect to 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()); }
However, I got an error
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) ......
I googled online, and the suggestion is to set the signature to version 4, which I did already. Any thoughts?
Note my aws jdk is pretty dated as I cannot upgrade it due to some other libs conflicts.
Advertisement
Answer
Setting AWS SDK client configuration to V4 Signature
Java:
ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setSignerOverride("AWSS3V4SignerType"); AmazonS3 AmazonS3 = AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfig) .build();
NodeJs:
new S3({ signatureVersion: 'v4' })