簡體   English   中英

AWS S3如何將文件從存儲桶移動到其他區域的另一個存儲桶

[英]AWS S3 How to move files from a bucket to another bucket in a different region

我在不同地區有兩個存儲桶,B1位於APSoutheast2(悉尼),另一個(B2)位於USWest1(美國西部(加利福尼亞北部))。 我正在嘗試使用AWS S3 SDK(.NET)將某些文件從B1移到B2,但似乎看不到一種簡單的方法。

這是我的示例代碼:

var sydneyClient = new AmazonS3Client("accessKeyID", "secretKey", 
RegionEndpoint.APSoutheast2)
var fileInfo = new S3FileInfo(sydneyClient, "b1", "filePath");
if (!fi.Exists)
{
    return;
}
fileInfo.MoveTo("b2", "filePath");

這給了我以下錯誤:

Amazon.S3.AmazonS3Exception: 'Error making request with Error Code 
MovedPermanently and Http Status Code MovedPermanently. No further error 
information was returned by the service.'

我認為這是因為b2與執行此操作時位於不同的區域中:

var listAllRequest = new ListObjectsRequest();
listAllRequest.BucketName = "b2";
var listAllResponse = sydneyClient.ListObjects(listAllRequest);

我懂了:

The bucket you are attempting to access must be addressed using the specified 
endpoint. Please send all future requests to this endpoint

我知道我的“ sydneyClient”無法訪問在美國創建的另一個存儲桶是有道理的,因為我在創建該存儲桶時將其指定為“ RegionEndpoint.APSoutheast2”,並且根據AWS文檔每個區域都是獨立的。

如果我嘗試將文件從b1移到APSoutheast2中的另一個存儲桶,則可以正常工作。

我知道我可以將文件從b1下載到本地存儲,為b2創建另一個AmazonS3Client,然后執行上傳。 但是在這種情況下,是否有一種簡單的方法將文件從b1移到另一個區域中的存儲桶?

謝謝

Amazon S3沒有“移動”命令。 相反,您應該使用AmazonS3Client.CopyObject方法 ,並指定:

public virtual CopyObjectResponse CopyObject(
         String sourceBucket,
         String sourceKey,
         String destinationBucket,
         String destinationKey
)

然后,刪除原始對象。

這適用於存儲桶之間以及區域之間。 將請求發送到目標區域 (即,目標桶所在的區域)。

您可以直接使用AWS Management Portal進行配置,而無需更改任何代碼。

此功能稱為S3跨區域復制(簡稱CRR)。

他們在這里安裝指南

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM