簡體   English   中英

AWS- S3 多區域訪問點在 C# 中的使用

[英]AWS- S3 Multi-Region Access point use in C#

實際上,我需要在我的 c# 應用程序中使用 s3 多區域功能。

我在我的項目中安裝了 AWSSDK dll。

我創建了 3 個不同區域的存儲桶,例如 us-west-2、us-east-1 和 us-east2。 並在創建多區域接入點時添加了這 3 個存儲桶。

創建此接入點后,我只是從 s3 多區域板復制了 ARN 名稱並在我的 c# 代碼中使用了它,我只是用多區域接入點替換了存儲桶名稱我的代碼如下所示:

var config=new AmazonS3Config();
config.UseArnRegion=false;
config.RegionEndPoint=RegionEndPoint.USWest2;

var s3Client=new AmazonS3Client(config);

before using multi region the code was like this and its working:
S3FileInfo info=new S3FileInfo(s3Client, "s3bucketname","Dummy.txt");

and after adding the multi region the code look like this and getting below error:
S3FileInfo info=new S3FileInfo(s3Client, "arn:aws:s3::\<account_number\>/---.mrap","Dummy.txt");

i have tried this below 2 options also but its not working getting error "The specified bucket is does not exist.."
S3FileInfo info=new S3FileInfo(s3Client, "---.mrap","Dummy.txt");
S3FileInfo info=new S3FileInfo(s3Client, "---.mrap.accesspoint.s3-global.amazonaws.com","Dummy.txt");

bool fileExist=info.Exists;

MessageBox.Show(fileExist.ToString());

我收到如下錯誤:Amazon.Runtime.AWSCommonRuntimeException:嘗試發出需要實施 AWS Signature V4a 的請求。 將對 AWSSDK.Extensions.CrtIntegration NuGet package 的引用添加到您的項目以包含 AWS Signature V4a 簽名者。

請讓我知道我哪里錯了。 請幫我解決這個問題。

這是適合您的解決方案。

var mrapArn = "arn:aws:s3::{your-account-id-here}:accesspoint/{mrap-alias-here}";
string objKey = "folderA/folderB/abc.jpeg";

AWSConfigsS3.UseSignatureVersion4 = true;
var client = new AmazonS3Client(new AmazonS3Config { UseArnRegion = true });

var file = await client.GetObjectAsync(new GetObjectRequest { BucketName = mrapArn, Key = objKey });

Console.WriteLine(file.VersionId);

暫無
暫無

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

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