dimanche 2 août 2015

"The specified key does not exist" S3 error for really existing object in the bucket

In our application we have to download on backend by AWS Java SDK uploaded user's image for some processing operations(resize,crop,etc.) Sometimes, we get the following error:

com.amazonaws.services.s3.model.AmazonS3Exception: The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey;

but this key and the object which was saved by this path exist. I know that in AWS developer guide this behavior is expected:

However, information about the changes might not immediately replicate across Amazon S3 and you might observe the following behaviors: A process writes a new object to Amazon S3 and immediately attempts to read it. Until the change is fully propagated, Amazon S3 might report "key does not exist."

but how can I process this error in my code? I tried to wait some milliseconds,I tried to retry download this object - and all my attempts are failed.

         try
            {
                Download download = s3TransferManager
                        .download(new GetObjectRequest(bucketName, key), new File(tempUrl));
                download.waitForCompletion();
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                Thread.sleep(1000);
                //retry 3 time.... }

I would be glad to hear any advice how to download existing file in that case. Thank you!




Aucun commentaire:

Enregistrer un commentaire