How to set the EndPoint / Region for the C# .NET S

2019-02-21 14:23发布

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.

3条回答
祖国的老花朵
2楼-- · 2019-02-21 14:54

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

查看更多
贼婆χ
3楼-- · 2019-02-21 14:58

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"
    }
);
查看更多
我命由我不由天
4楼-- · 2019-02-21 15:16

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);
查看更多
登录 后发表回答