【发布时间】:2023-03-22 12:45:02
【问题描述】:
我的问题是关于我存储在具有存储类冰川的 S3 存储桶中的数据。我想用可用的最快选项检索它,但我找不到合适的方法来实现它。似乎默认请求正在使用标准检索选项。
在 aws 文档中,我找到了一种恢复数据的好方法。
来自here 我有这个代码示例:
import java.io.IOException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.RestoreObjectRequest;
public class RestoreArchivedObject {
public static void main(String[] args) throws IOException {
String clientRegion = "*** Client region ***";
String bucketName = "*** Bucket name ***";
String keyName = "*** Object key ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider())
.withRegion(clientRegion)
.build();
// Create and submit a request to restore an object from Glacier for two days.
RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucketName, keyName, 2);
s3Client.restoreObjectV2(requestRestore);
// Check the restoration status of the object.
ObjectMetadata response = s3Client.getObjectMetadata(bucketName, keyName);
Boolean restoreFlag = response.getOngoingRestore();
System.out.format("Restoration status: %s.\n",
restoreFlag ? "in progress" : "not in progress (finished or failed)");
}
catch(AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
e.printStackTrace();
}
catch(SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
}
这很好并且有效。但是如果我想在文档中进行选择,我没有在文档中找到如何设置检索选项:
- 批量检索 5-12 小时
- 快速试用 1-5 分钟
- 标准试用 3-5 小时
here 是来自 aws 文档的 RestoreObjectRequest 类。在那里我可以看到一个函数 setType(String type) 设置恢复请求类型。但是没有关于设置上述选项之一的描述(1-3)。如果有人能告诉我这是否可以用 java sdk aws 设置,那就太好了。
编辑:
Here 我可以读到 setTier(String tier) 应该这样做。 还原存档时要使用的数据访问层。标准是默认设置。
类型:枚举
有效值:加急 |标准 |散装
祖先:RestoreRequest 现在如果我将默认请求更改为:
RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucketName, keyName, 2).withTier("Standard");
线程“main”com.amazonaws.services.s3.model.AmazonS3Exception 中的异常:您提供的 XML 格式不正确或未针对我们发布的架构进行验证
以某种方式使用旧版本的 java sdk
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.386</version>
</dependency>
【问题讨论】:
-
您使用的是最新版本的适用于 Java 的 AWS 开发工具包吗?恢复对象时指定层的功能已有一年多的历史,但并不总是存在。
标签: java amazon-web-services amazon-s3 aws-java-sdk amazon-glacier