amazon-web-services - AWS S3 获取对象版本返回错误代码:500 内部服务器错误
问题描述
检索在 Localstack (docker) 上运行的 S3 中存储的对象版本时出现以下错误:
com.amazonaws.services.s3.model.AmazonS3Exception:内部服务器错误(服务:Amazon S3;状态代码:500;错误代码:500 内部服务器错误;请求 ID:空),S3 扩展请求 ID:空
我已经使用 aws-java-sdk 的 1.11.163、1.11.359、1.11.383 版本进行了测试。
列出和删除文件有效,但我无法使用 SDK 获取版本。
问题是,当使用 cli 时,我可以在我的存储桶中列出对象的版本。
列出我的存储桶中文件的版本时:
aws --endpoint-url= http://localhost:4572 s3api list-object-versions --bucket my-bucket --prefix testFolder
我得到以下输出:
{
"Versions": [
{
"LastModified": "2018-08-10T08:52:06.193Z",
"VersionId": "0",
"ETag": "\"da9a0adf68f7fa4da720e10914283cc9\"",
"StorageClass": "STANDARD",
"Key": "testFolder/test.txt",
"Owner": {
"DisplayName": "webfile",
"ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
},
"IsLatest": true,
"Size": 7366
},
{
"LastModified": "2018-08-10T08:52:06.188Z",
"VersionId": "0",
"ETag": "\"5f22390dd70444e4f3ea347313442a6d\"",
"StorageClass": "STANDARD",
"Key": "testFolder/0001/test.txt",
"Owner": {
"DisplayName": "webfile",
"ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
},
"IsLatest": true,
"Size": 2507
},
{
"LastModified": "2018-08-10T08:52:06.191Z",
"VersionId": "0",
"ETag": "\"9001b739dd280ace7b6b7ae45377484a\"",
"StorageClass": "STANDARD",
"Key": "testFolder/0001/test-other.txt",
"Owner": {
"DisplayName": "webfile",
"ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
},
"IsLatest": true,
"Size": 4589
},
{
"LastModified": "2018-08-10T08:52:06.185Z",
"VersionId": "0",
"ETag": "\"4d32ffe9a1f7e272c78aa80e95fb9cf3\"",
"StorageClass": "STANDARD",
"Key": "testFolder/test-other.txt",
"Owner": {
"DisplayName": "webfile",
"ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
},
"IsLatest": true,
"Size": 15549
}
]
}
这是我创建 S3Configuration 的方法:
private static S3Configuration s3Configuration() {
S3Configuration s3Configuration = new S3Configuration();
s3Configuration.setBucket("my-bucket");
return s3Configuration;
}
以下是我创建 AmazonS3 客户端的方法:
private static AmazonS3 amazonS3() {
final AWSCredentials credentials = new BasicAWSCredentials("foobar","foobar");
final EndpointConfiguration endpointConfiguration = new EndpointConfiguration("http://localhost:4572",DEFAULT_REGION.getName());
AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withEndpointConfiguration(endpointConfiguration)
.withPathStyleAccessEnabled(true);
return amazonS3ClientBuilder.build();
}
每当我尝试使用以下命令列出存储桶中文件的版本时,就会发生异常:
VersionListing versionListing = amazonS3.listVersions(new ListVersionsRequest().withBucketName(bucketName));
或尝试获取特定文件的版本:
VersionListing versionListing = amazonS3.listVersions(bucketName, objectKey);
从 S3ObjectSummary.getKey() 中检索 objectKey
知道我缺少什么吗?
谢谢你的帮助。
解决方案
好像是个bug
这应该可以解决您的问题
new ListVersionsRequest()
.withEncodingType("")
.withBucketName(bucketName)
.withPrefix(key);
推荐阅读
- regex - 我如何将我的正则表达式改进为 grep 三级域,但最后没有额外的字符?
- google-smart-home - 针对恒温器报告状态问题的 Google 智能家居操作
- javascript - 如何在渲染之前在实例上定义属性或方法
- html - 如何在 HTML 样式中包含 CSS 样式(通过 ASP.Net MVC Razor 页面生成的代码)
- laravel - 无效的道具:道具“活动”的类型检查失败。预期的布尔值,得到值为“true”的字符串
- php - 从 json_url 获取数据以及如何插入到我的 mysql 数据库
- visual-studio-code - 如何避免在vs代码中显示前导和尾随空格
- php - PHP - MySql:如何在 db 中存储来自 [输入文本] 和 [下拉值] 的值
- java - 无法弄清楚为什么此测试在向 ArrayList 添加项目时失败
- java - 如何在 java 8 中使用 IntStream 返回一个升序数组列表?