0

我正在使用 AWS .Net SDK 并尝试通过创建适当的客户端来查询 AWS 服务,如下所示

var cred = new BasicAWSCredentials(awsAccessKeyId, awsSecretKeyId);
using (AmazonEC2Client ec2Client = new AmazonEC2Client(cred, region))
{
    // code here  
}

上面的工作正常,但是还有一个 AmazonEC2Client 的重载方法,它不需要指定区域,但是当我尝试创建没有区域的客户端时,如下所示,它会给出错误:Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured

未配置 RegionEndpoint 或 ServiceURL

using (AmazonEC2Client ec2Client = new AmazonEC2Client(cred))
{
    // code here  
}

请让我知道上述代码是否有问题,或者是否有任何方法可以查询 AWS 服务,无论区域如何。

谢谢

4

1 回答 1

0

AWSConfigs.AWSRegion您可以使用该属性全局配置区域。

AWSConfigs.AWSRegion = "us-east-1";
using (var ec2Client = new AmazonEC2Client())
{
  // Make request to Amazon EC2 using ec2Client
}

或者您可以在文件的部分中设置AWSRegion密钥。appSettingsapp.config

<configuration>
  <appSettings>
    <add key="AWSRegion" value="us-west-2"/>
  </appSettings>
</configuration>

https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-region-selection.html

于 2019-07-19T07:29:44.740 回答