如何使用aws-sdk net自定义端点?

问题描述 投票:0回答:1

有人知道如何使用 s3 net API 添加自定义端点吗?
详细信息:https://github.com/aws/aws-sdk-net/issues/1283 代码语言:C#

sServiceUrl 值=“192.168.199.216:7480”

当我调用DoesS3BucketExist函数时,我取消了一个异常(System.UriFormatException)

这是我的代码

public IAmazonS3 CreateClient(string sAccessKeyId, string sAccessKeySecret, string sServiceUrl)
{
    AmazonS3Client s3Client = null;
    try
    {
         AmazonS3Config config = new AmazonS3Config();
         config.ServiceURL = sServiceUrl;
         config.UseHttp = false;
         config.SignatureVersion = "v4";
         AWSConfigsS3.UseSignatureVersion4 = true;

         s3Client = new AmazonS3Client(
                        sAccessKeyId,
                        sAccessKeySecret,
                        config
                        );
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog("AWS配置", ex, "创建AmazonS3Client失败!");
     }
     return s3Client;
}

public bool DoesBucketExist(string bucketName)
{
    bool bIsExist;
    if (this.Client != null)
    {
        bIsExist = this.Client.DoesS3BucketExist(bucketName);
    }
    else
    {
        bIsExist = false;
    }
    return bIsExist;
}

我想设置这个属性

AWSConfigs.EndpointDefinition = @"c:pathtoendpoints.xml";
,但我不知道如何自定义endpoints.json文件。

这对我来说太难了,也许我需要上帝帮助我!任何帮助将不胜感激!

aws-sdk aws-sdk-net
1个回答
4
投票
static void Main(string[] args)
    {
        string accessKey = "";
        string secretKey = "";

        AmazonS3Config config = new AmazonS3Config()
        {
            ServiceURL = string.Format("http://{0}", "192.168.199.216:7480"),
            UseHttp = true,
            ForcePathStyle = true,
            ProxyHost = "192.168.199.216",
            ProxyPort = 7480
        };

        AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
        AmazonS3Client s3Client = new AmazonS3Client(creds, config);
        try
        {
            ListBucketsResponse response = s3Client.ListBuckets();
            foreach (S3Bucket b in response.Buckets)
            {
                Console.WriteLine("{0}\t{1}", b.BucketName, b.CreationDate);
            }
        }
        catch (Exception ex)
        {

            throw;
        }
© www.soinside.com 2019 - 2024. All rights reserved.