Closed yh371174229 closed 5 years ago
I found this https://github.com/aws/aws-sdk-net/issues/679 but I don't know how to solve my problem using C#
Is this what you're looking for? https://aws.amazon.com/blogs/developer/overriding-endpoints-in-the-aws-sdk-for-net/
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.
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:https://github.com/localstack/localstack/issues/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.
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;
}
Does anyone konw how to add custom endpoint using s3 net API??