0

I am facing a strange issue (might be related to bucket policy) with s3 upload. When I am trying to upload a file using aws cli along with sse-kms, it is getting uploaded without any issue. But, when I am trying to upload the same file with aws-java-sdk (1.9.5), it says AceessDenied.

It might be related to bucket policy but I am wondering how it can be possible that file can be uploaded by aws cli but not with aws-java-sdk.

Following is the aws cli for uploading [this is working fine]:

aws s3 cp file.zip s3://my-bucket --sse aws:kms --sse-kms-key-id arn:aws:kms:eu-west-1:my_account_id:key/kms_key

Here is aws-java-sdk api code snippet [this says Accessdenied]:

val bucket = "my-bucket"
val AWS_ACCESS_KEY = "access_key"
val AWS_SECRET_KEY = "secret_key"
val awsCredentials = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)
val clientConfiguration = new ClientConfiguration
clientConfiguration.setSignerOverride("AWSS3V4SignerType")
clientConfiguration.withSignerOverride("AWSS3V4SignerType")
val amazonS3Client = new AmazonS3Client(awsCredentials, clientConfiguration)
amazonS3Client.setRegion(com.amazonaws.regions.Region.getRegion(Regions.EU_WEST_1))
val KMS_ID = "arn:aws:kms:eu-west-1:my_account_id:key/kms_key"
val kmsKey = new SSEAwsKeyManagementParams(KMS_ID)
val file = new File("/home/vikash/file.zip")
val putRequest = new PutObjectRequest(bucket, "file.zip", file).withSSEAwsKeyManagementParams(kmsKey)
val response = amazonS3Client.putObject(putRequest)

Could anyone please suggest, what I am missing here? your suggestion will be much appreciated.

Best Regards,

Vikash Pareek

Vikash Pareek
  • 1,063
  • 14
  • 30
  • Have you tried setting the signature v4 as described in this Amazon document: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html – krishna_mee2004 Dec 14 '17 at 12:44
  • This is already there in aws-java-sdk-1.9.5. although, I have configured it manually as well. P.S. clientConfiguration.setSignerOverride("AWSS3V4SignerType") clientConfiguration.withSignerOverride("AWSS3V4SignerType") – Vikash Pareek Dec 15 '17 at 05:07

0 Answers0