Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to custom endpoint #1283

Closed
yh371174229 opened this issue May 7, 2019 · 4 comments
Closed

how to custom endpoint #1283

yh371174229 opened this issue May 7, 2019 · 4 comments
Labels
guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@yh371174229
Copy link

Does anyone konw how to add custom endpoint using s3 net API??

@yh371174229
Copy link
Author

I found this https://github.com/aws/aws-sdk-net/issues/679
but I don't know how to solve my problem using C#

@klaytaybai klaytaybai added the guidance Question that needs advice or information. label May 7, 2019
@klaytaybai
Copy link
Contributor

@klaytaybai klaytaybai added closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels May 7, 2019
@yh371174229
Copy link
Author

yh371174229 commented May 8, 2019

First thanks for replying。
This is my code,the sServiceUrl value="192.168.199.216:7480"

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

This is my s3 browser ,the browser can successfully create and use.
image

I Can create client successfully,but when i call DoesS3BucketExist,it will cause a Exception

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

it told me that it's a invilad uri(System.UriFormatException),I don't know if I missed something.
Additional Information:I use localstack.
I found this issue:localstack/localstack#942

        static void Main(string[] args)
        {
            string accessKey = "";
            string secretKey = "";

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

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

        }

Error unmarshalling response back from AWS
but still not solve my problem.

@yh371174229
Copy link
Author

yh371174229 commented May 8, 2019

I have solved it。Life is so beautiful,but the aws doc is so bad.
Leave the code here,maybe help somebody.Reference the information

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

@klaytaybai klaytaybai removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants