如何使用 Amazon AWS SDK for C# 访问 Eucalyptus Walrus(S3)
我已经下载了适用于 C# 的 Amazon AWS SDK,访问运行 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());
}
但是我需要访问我们的云的 Walrus (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 网站:
Eucalyptus 实现了 IaaS (基础设施即服务)私有 可通过 API 访问的云 与亚马逊EC2和亚马逊兼容 S3
我错过了什么?
注意:相同的代码可以在 Amazon S3 上完美运行,问题在于访问 Eucalyptus Walrus。
I have downloaded the Amazon AWS SDK for C#, I have no problem accessing the EC2 part of our private cloud running Eucalyptus, I can list, Images, Instances, Zones ...
This is working fine :
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());
}
But I need to access the Walrus (S3) part of our Cloud. This is how I try to access the Walrus, the code is almost identical, but with this call I will get an exception.
This is not working:
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());
}
I will receive this exception :
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
From Eucalyptus site :
Eucalyptus implements an IaaS
(Infrastructure as a Service) private
cloud that is accessible via an API
compatible with Amazon EC2 and Amazon
S3
What am I missing ?
Note: The same code work flawlessly with Amazon S3, the problem is to access Eucalyptus Walrus.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用当前适用于 C# 的 Amazon AWS 开发工具包访问 Walrus。如果您的 Walrus URL 包含类似以下的路径组件,它的工作方式与您期望的方式不一样:
http://eucalyptus.test.local:8773/services/Walrus
以下是如何设置 AmazonS3Client 和请求。请注意,服务 url 的路径部分被放入存储桶名称中。
我已经使用预先签名的 url 和 DeleteObjectRequest 测试了此设置。我正在使用 https://github.com/aws/aws 的 SDK 版本 1.5.19.0 -sdk-net
You can access Walrus using the current Amazon AWS SDK for C#. It just doesn't work quite the way you would expect if your Walrus URL contains a path component like...
http://eucalyptus.test.local:8773/services/Walrus
Here's how to setup the AmazonS3Client and a request. Notice that the path portion of the service url gets put into the bucketname.
I've tested this setup with presigned urls and with the DeleteObjectRequest. I'm using version 1.5.19.0 of the SDK from https://github.com/aws/aws-sdk-net
AWSSDK for .NET 似乎无法理解 ServiceUrls 中的端口号...前几天我刚刚在 SimpleDB 客户端代码中为此编写了一个补丁,但我实际上还没有在 S3 客户端中查看过它
...可以尝试在端口 80 上临时托管您的 Walrus 服务,然后重新测试以验证这是否是问题所在。
AWSSDK for .NET doesn't seem to understand port numbers in ServiceUrls... I just wrote a patch for this in the SimpleDB client code the other day, but I haven't actually looked at it in the S3 client...
You could try temporarily hosting you Walrus service on port 80 and retesting to verify if this is the problem.