gpt4 book ai didi

c# - 如何使用 Amazon AWS SDK for C# 访问 Eucalyptus Walrus(S3)

转载 作者:行者123 更新时间:2023-11-30 12:35:03 25 4
gpt4 key购买 nike

我已经下载了适用于 C# 的 Amazon AWS SDK,我可以毫无问题地访问我们运行 Eucalyptus 的私有(private)云的 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) 部分。这就是我尝试访问 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 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。

最佳答案

您可以使用当前适用于 C# 的 Amazon AWS SDK 访问 Walrus。如果您的 Walrus URL 包含类似...的路径组件,它就不会像您期望的那样工作

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

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

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

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"));

关于c# - 如何使用 Amazon AWS SDK for C# 访问 Eucalyptus Walrus(S3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6280919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com