I'm working on an Amazon s3 Compatible Object Storage solution (Minio).
I have an Minio server on e.g 192.168.235.143:9000
I have tried to get List of buckets on C# version of Amazon s3 Api. Everything works fine.
When I try to Put a Bucket into this server e.g test1
, Visual studio throws this request into an Exception:
Amazon.Runtime.AmazonServiceException:
'A WebException with status NameResolutionFailure was thrown.'
WebException: The remote name could not be resolved: 'test1.192.168.235.143'
here is my code:
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "192.168.235.143:9000";
AmazonS3Client client = new AmazonS3Client(AccessKey, SecretKey, config);
PutBucketRequest request = new PutBucketRequest();
request.BucketName = "test1";
// this Line will throws above exception :
client.PutBucket(request);
but ListBuckets
works for make me confused:
AmazonS3Client client = new AmazonS3Client(AccessKey, SecretKey, config);
var response = client.ListBuckets();
foreach (S3Bucket b in response.Buckets)
{
MessageBox.Show(string.Format("{0}\t{1}", b.BucketName, b.CreationDate));
}
What i have tested to check this Exception's cause:
port #80
I need to use a known interface so we be able to port into another Object Storage Platform e.g Ceph, ....
I have no Idea to get it resolved yet.
Please Help me to find my mistake or a better solution
Here i have found a sample working code, Thanks to Minio GitHub Community:
using Amazon.S3;
using System;
using System.Threading.Tasks;
using Amazon;
class Program
{
private const string accessKey = "PLACE YOUR ACCESS KEY HERE";
private const string secretKey = "PLACE YOUR SECRET KEY HERE"; // do not store secret key hardcoded in your production source code!
static void Main(string[] args)
{
Task.Run(MainAsync).GetAwaiter().GetResult();
}
private static async Task MainAsync()
{
var config = new AmazonS3Config
{
RegionEndpoint = RegionEndpoint.USEast1, // MUST set this before setting ServiceURL and it should match the `MINIO_REGION` enviroment variable.
ServiceURL = "http://localhost:9000", // replace http://localhost:9000 with URL of your MinIO server
ForcePathStyle = true // MUST be true to work correctly with MinIO server
};
var amazonS3Client = new AmazonS3Client(accessKey, secretKey, config);
// uncomment the following line if you like to troubleshoot communication with S3 storage and implement private void OnAmazonS3Exception(object sender, Amazon.Runtime.ExceptionEventArgs e)
// amazonS3Client.ExceptionEvent += OnAmazonS3Exception;
var listBucketResponse = await amazonS3Client.ListBucketsAsync();
foreach (var bucket in listBucketResponse.Buckets)
{
Console.Out.WriteLine("bucket '" + bucket.BucketName + "' created at " + bucket.CreationDate);
}
if (listBucketResponse.Buckets.Count > 0)
{
var bucketName = listBucketResponse.Buckets[0].BucketName;
var listObjectsResponse = await amazonS3Client.ListObjectsAsync(bucketName);
foreach (var obj in listObjectsResponse.S3Objects)
{
Console.Out.WriteLine("key = '" + obj.Key + "' | size = " + obj.Size + " | tags = '" + obj.ETag + "' | modified = " + obj.LastModified);
}
}
}
}