c#中的AWS- S3多区域接入点使用



实际上,我需要在我的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包的引用,以包含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);

相关内容

  • 没有找到相关文章

最新更新