4

我已经下载了适用于 C# 的 Amazon AWS 开发工具包,我可以毫无问题地访问运行 Eucalyptus 的私有云的 EC2 部分,我可以列出、图像、实例、区域......

这工作正常:

AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client("abcdefghijklmnopqrstuvwxyz1234567890", "abcdefghijklmnopqrstuvwxyz1234567890", new AmazonEC2Config().WithServiceURL("http://10.140.54.12:8773/services/Eucalyptus"));

DescribeInstancesRequest ec2Request = new DescribeInstancesRequest();
try
{
    DescribeInstancesResponse ec2Response = ec2.DescribeInstances(ec2Request);
    int numInstances = 0;
    numInstances = ec2Response.DescribeInstancesResult.Reservation.Count;
    textBoxInstancesLog.AppendText("You have " + numInstances + " running instances");
    textBoxInstancesLog.AppendText(ec2Response.ToString());
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}

但我需要访问我们云的海象(S3)部分。这就是我尝试访问海象的方式,代码几乎相同,但是通过这个调用我会得到一个异常。

这不起作用:

AmazonS3 s3 = AWSClientFactory.CreateAmazonS3Client("abcdefghijklmnopqrstuvwxyz1234567890", "abcdefghijklmnopqrstuvwxyz1234567890", new AmazonS3Config().WithServiceURL("http://10.140.54.12:8773/services/Walrus"));
ListBucketsRequest s3Request = new ListBucketsRequest();
try
{
    ListBucketsResponse s3Response = s3.ListBuckets(s3Request);
    textBoxS3Log.AppendText(s3Response.ToString());
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}

我会收到这个例外:

System.Net.WebException: The remote name could not be resolved: 'http'
   at Amazon.S3.AmazonS3Client.processRequestError(String actionName, HttpWebRequest request, WebException we, HttpWebResponse errorResponse, String requestAddr, WebHeaderCollection& respHdrs, Type t, Exception& cause)
   at Amazon.S3.AmazonS3Client.handleHttpWebErrorResponse(S3Request userRequest, WebException we, HttpWebRequest request, HttpWebResponse httpResponse, Exception& cause, HttpStatusCode& statusCode)
   at Amazon.S3.AmazonS3Client.getResponseCallback[T](IAsyncResult result)
   at Amazon.S3.AmazonS3Client.endOperation[T](IAsyncResult result)
   at Amazon.S3.AmazonS3Client.ListBuckets(ListBucketsRequest request)
   at IAASClient.FormMain.buttonS3Test_Click(Object sender, EventArgs e) in X:\work\IAASClient\FormMain.cs:line 107

来自桉树网站:

Eucalyptus 实施 IaaS(基础设施即服务)私有云,可通过与 Amazon EC2 和 Amazon S3 兼容的 API 访问

我错过了什么?

注意:相同的代码在 Amazon S3 上完美运行,问题是访问 Eucalyptus Walrus。

4

2 回答 2

2

您可以使用当前适用于 C# 的 Amazon AWS 开发工具包访问 Walrus。如果您的海象 URL 包含一个路径组件,例如...

http://eucalyptus.test.local:8773/services/Walrus

以下是设置 AmazonS3Client 和请求的方法。请注意,服务 url 的路径部分被放入存储桶名称中。

我已经使用预签名的 url 和 DeleteObjectRequest 测试了这个设置。我正在使用来自https://github.com/aws/aws-sdk-net的 SDK 1.5.19.0 版本

var config = new Amazon.S3.AmazonS3Config
                {
                    ServiceURL = "eucalyptus.test.local:8773",
                    CommunicationProtocol = Protocol.HTTP
                };

            var client = new Amazon.S3.AmazonS3Client("XXXXXXXXXXXXXXXXXXKEY", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXSECRET", config);
            var response = client.GetPreSignedURL(
                new GetPreSignedUrlRequest().WithBucketName("services/Walrus/BucketName")
                                            .WithExpires(DateTime.UtcNow.AddHours(10))
                                            .WithProtocol(Protocol.HTTP)
                                            .WithVerb(HttpVerb.PUT)
                                            .WithKey("video.mp4"));
于 2013-05-10T17:28:12.010 回答
0

适用于 .NET 的 AWSSDK 似乎不理解 ServiceUrls 中的端口号...前几天我刚刚在 SimpleDB 客户端代码中为此编写了一个补丁,但我实际上并没有在 S3 客户端中查看它...

您可以尝试在端口 80 上临时托管您的 Walrus 服务并重新测试以验证这是否是问题所在。

于 2011-06-09T22:35:28.403 回答