AWS SDK for .NET。您提供的授权机制不受支持

时间:2017-03-09 14:24:33

标签: c# .net amazon-web-services amazon-s3 aws-sdk

发送ListObjectRequest时收到了下一个错误:

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256

根据this回答,AmazonS3Config按以下方式更新:

var amazonS3Config = new AmazonS3Config
{
    SignatureVersion = "4",
    ServiceURL = bucketName,
    RegionEndpoint = RegionEndpoint.USEast1,
    SignatureMethod = SigningAlgorithm.HmacSHA256
};

var s3Client = new AmazonS3Client(accessKeyID, secretKey, amazonS3Config);

但我仍然收到此错误。我错过了什么?

感谢。

2 个答案:

答案 0 :(得分:1)

尝试使用amazonS3 sdk的最新版本。我认为当您知道regionEndpoint时我不需要ServiceUrl,我将它用于私有云amazonS3并且当我不知道Region Endpoint时。我可以使用以下代码从Amazon检索信息。

        var amazonS3Config = new AmazonS3Config();
        // region of FrankPurt is : RegionEndpoint.EUCentral1
        // according to amazonS3 Doc http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
        amazonS3Config.RegionEndpoint = RegionEndpoint.USEast1;

        var s3Client = new AmazonS3Client("your access key", "your secret key", amazonS3Config);
         S3DirectoryInfo dir = new S3DirectoryInfo(s3Client, "your bucket name", "your folder path without bucket name");
        Console.WriteLine(dir.GetFiles().Count());

答案 1 :(得分:0)

通过这种方式,我可以在欧盟西部2地区工作

            AmazonS3Config config = new AmazonS3Config();
            config.SignatureVersion = "4";
            config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("eu-west-2");
            config.SignatureMethod = Amazon.Runtime.SigningAlgorithm.HmacSHA256;

区域应