Amazon S3发布SSL以使用c#sdk

时间:2011-01-27 15:13:15

标签: c# amazon-s3 amazon-web-services

我正在使用Amazon AWS .NET SDK v1.2.1。

以下代码在myBucket.more.https的DNS查找失败后抛出异常,这显然不是它应该寻找的......

AmazonS3Config S3Config = new AmazonS3Config()
{
    ServiceURL = "https://s3.amazonaws.com",
    CommunicationProtocol = Amazon.S3.Model.Protocol.HTTPS,
};

using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey,secretKey, S3Config))
{
    PutObjectRequest request = new PutObjectRequest();

    using (MemoryStream ms = new MemoryStream(inputBytes))
    {
        request.WithBucketName("myBucket.more")
                .WithKey(output.Name)
                .WithInputStream(ms);

        using (S3Response response = client.PutObject(request))
        {
                        Log.Message("File Sent: " + output.Name);
        }
    }
}

如果我从ServiceURL的前面删除https://,它会抛出一个Web异常:

"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

那我怎么想让SSL工作呢?

我到目前为止管理的唯一方法是使用以下内容,这是不安全的:

AmazonS3Config S3Config = new AmazonS3Config()
{
    ServiceURL = "s3.amazonaws.com",
    CommunicationProtocol = Amazon.S3.Model.Protocol.HTTP,
};

更新

如果我没有将自定义S3Config传递给CreateAmazonS3Client,它仍然会失败:

"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

"The remote certificate is invalid according to the validation procedure."

1 个答案:

答案 0 :(得分:7)

ServiceUrl应该是S3.amazonaws.com,前面没有https://。这是HTTPS协议的默认设置Communication。这就是为什么当您不手动设置设置时会出现相同的错误。

更新

如果您要使用HTTPS,则欧盟存储桶名称中不能包含句点(。)。