13

In the JAVA SDK it's possible to set the endpoint, see here.

But how to do this for .NET SDK ? And what are the names to use?

Because it seems that a default endpoint "US East (Northern Virginia) Region" is always used.

Community
  • 1
  • 1
Stef Heyenrath
  • 7,870
  • 9
  • 54
  • 100

3 Answers3

25

You can also use an endpoint definitions delivered with Amazon SDK:

var ec2Client = new AmazonEC2Client(RegionEndpoint.EUWest1);

Since I believe hard-coding such values as endpoint addresses is not a best practice I use more configurable version (i.e. endpoint configured from web.config/app.config):

var region = RegionEndpoint.GetBySystemName("eu-west-1");
var ec2Client = new AmazonEC2Client(region);
Marek
  • 1,512
  • 1
  • 28
  • 43
  • 4
    This should be the correct answer. Also I came across this while I was looking for a list of possible SystemName Strings that could be passed to the GetBySystemName method... Though I did not find the answer here I did find it at https://github.com/xamarin/amazon/blob/master/AWSSDK/RegionEndpoint.cs for anyone else that comes across this question looking for valid SystemName values. – DVS Apr 17 '17 at 20:34
  • 1
    GetBySystemName very helpful! – levis84 May 24 '21 at 13:15
9

Regions and Endpoints can be found here.

And example how to connect to EU:

AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client("key", "secret",
    new AmazonEC2Config
    {
        ServiceURL = "http://ec2.eu-west-1.amazonaws.com"
    }
);
Stef Heyenrath
  • 7,870
  • 9
  • 54
  • 100
2

You can also define the aws region in your configuration file using the region code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="AWSProfileName" value="default"/>
    <add key="AWSRegion" value="eu-west-1"/>
  </appSettings>
</configuration>

Then you can simply instanciate your ec2Client without any region:

var ec2Client = new AmazonEC2Client();
Console.WriteLine(ec2Client.Config.RegionEndpoint.DisplayName);

Output:

EU West (Ireland)

Regions and endpoint are defined here: http://docs.aws.amazon.com/general/latest/gr/rande.html

asidis
  • 1,134
  • 11
  • 21