No RegionEndpoint or ServiceURL configured

xiehongguang picture xiehongguang · Jul 12, 2017 · Viewed 30.8k times · Source

I am writing code to upload files to AWS S3 and receiving this exception:

AmazonClientException: No RegionEndpoint or ServiceURL configured

My code:

Console.WriteLine("ready to upload");
AWSCredentials credentials;
credentials = new BasicAWSCredentials(accessKeyID.Trim(), secretKey.Trim());
AmazonS3Client s3Client = new AmazonS3Client(accessKeyID.Trim(), secretKey.Trim(), Amazon.RegionEndpoint.USEast1);
Console.WriteLine("Successful verification");
Console.WriteLine("Check if the bucket exists");
if (!CheckBucketExists(s3Client, bucketName))
{
    s3Client.PutBucket(bucketName);
    Console.WriteLine("create bucket");
}
TransferUtility utility = new TransferUtility();
Console.WriteLine("Upload  Directory......");
//exception here
utility.UploadDirectory(@"E:\telerikFile\13ginabdfglil.com", bucketName);

The exception:

Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured
  Amazon.Runtime.ClientConfig.Validate()
  Amazon.S3.AmazonS3Config.Validate()
  Amazon.Runtime.AmazonServiceClient..ctor(AWSCredentials credentials, ClientConfig config)
  Amazon.S3.AmazonS3Client..ctor()
  Amazon.S3.Transfer.TransferUtility..ctor()
  Telerik2Amazon.Program.UploadFile()

What should I do?

Answer

Drew Noakes picture Drew Noakes · Sep 16, 2017

The short answer to error...

Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured

...in my case was to specify a region when constructing the client object (for me it was AmazonSimpleEmailServiceClient).

Assuming you're using BasicAWSCredentials then try this:

var credentials = new BasicAWSCredentials(accessKeyID, secretKey);

new AmazonS3Client(credentials, RegionEndpoint.USEast1);

//                              ^^^^^^^^^^^^^^^^^^^^^^  add this