AWS S3 Get对象版本返回错误代码:500 Internal Server Error

时间:2018-08-10 09:22:07

标签: amazon-web-services amazon-s3 atlassian-localstack

检索在Localstack(docker)上运行的S3中存储的对象的版本时出现以下错误:

  

com.amazonaws.services.s3.model.AmazonS3Exception:内部服务器错误(服务:Amazon S3;状态代码:500;错误代码:500内部服务器错误;请求ID:空),S3扩展请求ID:空< / p>

我已经用aws-java-sdk的1.11.163、1.11.359和1.11.383版进行了测试。

列出并删除文件是可行的,但是我无法使用SDK来获取版本。

问题是,使用cli时,我可以在存储桶中列出对象的版本。

列出我的存储桶中文件的版本时:

  

aws --endpoint-url = http://localhost:4572 s3api列表对象版本--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的位置

对我想念的东西有任何想法吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

好像是个错误

这应该可以解决您的问题

new ListVersionsRequest()
                        .withEncodingType("")
                        .withBucketName(bucketName)
                        .withPrefix(key);