繁体   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