0
votes

i used following code to copy file from one bucket to other bucket

AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
s3client.copyObject(sourceBucketName, sourceKey, 
                    destinationBucketName, destinationKey);

but i alway get "com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: B6466D562B6988E2)"` as the respone what may be the reason for that

2
Maybe Error Code: AccessDeniedScary Wombat
what? Error Code: AccessDeniedAfsal Salim
i have read and write permission then how access denied?Afsal Salim
Where are you getting the credentials -- is the code running on an Amazon EC2 instance with an attached Role, or are you supplying credentials in a configuration file? Do those credentials have permission to read the source object and to write the destination object? What are the Bucket Policies on each bucket and/or what IAM permissions have been assigned? (You can update your Question to show the permissions.) What do you mean by "I have read and write permissions" -- how are they assigned? Basically, the error message is saying that something doesn't have sufficient permissions.John Rotenstein
"i have read and write permission " meant that using that access token i can read and write to that specific bucketAfsal Salim

2 Answers

1
votes

There can be lot of possibilities for getting such an error (like non-existent bucket, permissions issues, custom policy applied on source or target buckets etc.) I will recommend to setup AWS S3 CLI on your machine and try different s3 commands to make sure that you actually have right set of permissions to do the operation. This will allow you to iterate fast and debug issue quickly. I am not against writing Java code here to do the same but cli will definitely save time for you.

Also look this SO link to see if this helps you in fixing your problem.

-1
votes

now i copy the file using java aws sdk This is due to the absence of meta data while cpoying the file so we must add the meta data using copy copyObjRequest.setNewObjectMetadata(objectMetadata); ref http://docs.aws.amazon.com/AmazonS3/latest/dev/SSEUsingJavaSDK.html for the details