java “指定的键不存在”存储桶中真正存在的对象的 S3 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31772879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"The specified key does not exist" S3 error for really existing object in the bucket
提问by ZaptoS
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:
在我们的应用程序中,我们必须在后端下载 AWS Java SDK 上传的用户图像以进行一些处理操作(调整大小、裁剪等)有时,我们会收到以下错误:
com.amazonaws.services.s3.model.AmazonS3Exception: The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey;
com.amazonaws.services.s3.model.AmazonS3Exception:指定的键不存在。(服务:Amazon S3;状态代码:404;错误代码: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:
但是这个键和这个路径保存的对象是存在的。我知道在 AWS 开发人员指南中会出现这种行为:
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."
但是,有关更改的信息可能不会立即跨 Amazon S3 复制,您可能会观察到以下行为: 进程将新对象写入 Amazon S3 并立即尝试读取它。在更改完全传播之前,Amazon S3 可能会报告“密钥不存在”。
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!
在这种情况下,我很高兴听到有关如何下载现有文件的任何建议。谢谢!
回答by Mircea
The answer really depends on the region you are using. From S3 FAQ (here http://aws.amazon.com/s3/faqs/):
答案实际上取决于您使用的地区。来自 S3 常见问题解答(这里是http://aws.amazon.com/s3/faqs/):
Q: What data consistency model does Amazon S3 employ?
Amazon S3 buckets in all Regions provide read-after-write consistency for PUTS of new objects and eventual consistency for overwrite PUTS and DELETES. Amazon S3 buckets in the US Standard Region only provide read-after-write consistency when accessed through the Northern Virginia endpoint (s3-external-1.amazonaws.com).
问:Amazon S3 采用什么数据一致性模型?
所有区域中的 Amazon S3 存储桶为新对象的 PUTS 提供先写后读一致性,并为覆盖 PUTS 和 DELETES 提供最终一致性。美国标准区域中的 Amazon S3 存储桶仅在通过北弗吉尼亚终端节点 (s3-external-1.amazonaws.com) 访问时提供先写后读一致性。
If using US Standard and don't specify an endpoint you might experience large delays in edge cases between the put and when the object is available (anecdotally I've observed delays that are measured in hours). The pattern to follow is to execute the put and after that to spin and wait for the object.
如果使用美国标准并且不指定端点,则在放置和对象可用之间的边缘情况下,您可能会遇到很大的延迟(有趣的是,我已经观察到以小时为单位的延迟)。要遵循的模式是执行放置,然后旋转并等待对象。
The immediate fix is to use the Virginia endpoint (per FAQ) is case of US Standard or to move away from US standard and use another region (for example US-West-2). All other regions have read-after-write so the object will become available once the put is completed.
直接解决方法是使用弗吉尼亚端点(根据常见问题解答)是美国标准的情况,或者远离美国标准并使用另一个区域(例如 US-West-2)。所有其他区域都具有先写后读功能,因此一旦放置完成,该对象将变得可用。
回答by Edward Samuel
If your image processing is a background job (async job), you can use S3 Event Notification. So, whenever your image are has just put on a bucket, S3 can trigger a SNS notification/SQS or call AWS Lambda function.
如果您的图像处理是后台作业(异步作业),您可以使用S3 事件通知。因此,只要您的图像刚刚放入存储桶,S3 就可以触发 SNS 通知/SQS 或调用 AWS Lambda 函数。