using System; using Amazon.S3; using Amazon.S3.Model;
namespace ListBuckets { class Program { static void Main(string[] args) { var Ak = "xxx"; var Sk = "xxx"; var endpoint = "http://s3.test.com";
AmazonS3Client serviceClient = new AmazonS3Client(Ak,Sk, new AmazonS3Config{ ServiceURL = endpoint });
try { ListBucketsResponse resp; resp = serviceClient.ListBucketsAsync().GetAwaiter().GetResult();
Console.WriteLine($"Number of buckets: {resp.Buckets.Count}"); foreach (S3Bucket bucket in resp.Buckets) { Console.WriteLine("Bucket {0}, Created on {1}", bucket.BucketName, bucket.CreationDate); } } catch (AmazonS3Exception e) { Console.WriteLine(e.Message); throw; } catch (Exception e) { Console.WriteLine(e); throw; }
}
} } |