我已经下载了适用于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",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,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 implements an IaaS
(Infrastructure as a Service) private
cloud that is accessible via an API
compatible with Amazon EC2 and Amazon
S3
我错过了什么?
注意:相同的代码与Amazon S3完美配合,问题是访问Eucalyptus Walrus.
解决方法
您可以使用当前的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"));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。