如何使用AWS SDK网络自定义端点?

时间:2019-05-08 08:15:45

标签: aws-sdk aws-sdk-net

有人知道如何使用s3 net API添加自定义终结点吗?
详细信息:Like in below picture , outer circle will only rotate with their child circle but not the inner one 代码语言:C#

sServiceUrl值=“ 192.168.199.216:7480”

当我调用DidS3BucketExist函数时,我收到了异常(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文件。

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

1 个答案:

答案 0 :(得分:0)

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;
        }