我已经下载了适用于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());
}
但我需要访问Cloud的Walrus(S3)部分。这就是我尝试访问Walrus的方式,代码几乎完全相同,但是通过这个调用我会得到一个例外。
这不起作用:
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访问的云 与Amazon EC2和Amazon兼容 S3
我错过了什么?
注意:相同的代码与Amazon S3完美配合,问题是访问Eucalyptus Walrus。
答案 0 :(得分:2)
您可以使用当前的Amazon AWS SDK for C#访问Walrus。如果你的Walrus URL包含像...这样的路径组件,它就不会像你期望的那样工作。
http://eucalyptus.test.local:8773/services/Walrus
以下是设置AmazonS3Client和请求的方法。请注意,服务URL的路径部分将被放入bucketname。
我已使用预先指定的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"));
答案 1 :(得分:0)
AWSSDK for .NET似乎并不理解ServiceUrls中的端口号...我刚刚在SimpleDB客户端代码中为此编写了一个补丁,但我实际上并没有在S3客户端中查看它。 ..
您可以尝试在端口80上临时托管您的Walrus服务并重新测试以验证这是否是问题所在。