1

我一直在做一个亚马逊 EC2 项目,当我这样登录时:

public bool Login(Credentials credentials, string ownerID, string region)
{
    try
    {
        OwnerID = ownerID;
        CurrentCredentials = credentials;
        CurrentConfigs = new AmazonEC2Config() { RegionEndpoint = RegionEndpoint.GetBySystemName(region) };
        EC2 = AWSClientFactory.CreateAmazonEC2Client(CurrentCredentials, CurrentConfigs);
    }
    catch
    {
        return false;
    }
    return true;
}

然后尝试像这样访问:

DescribeInstancesRequest ec2Request = new DescribeInstancesRequest();
ec2Request.InstanceIds = new List<string>() { id };
DescribeInstancesResponse ec2Response = EC2.DescribeInstances(ec2Request);
return ec2Response.Reservations[0].Instances[0];

我得到这个例外:

例外:

Encountered a WebException (NameResolutionFailure), the request cannot be retried. Either the maximum number of retries has been exceeded (4/4) or the request is using a non-seekable stream.

堆栈跟踪:

at Amazon.Runtime.AmazonWebServiceClient.HandleHttpWebErrorResponse(AsyncResult asyncResult, WebException we)
at Amazon.Runtime.AmazonWebServiceClient.getRequestStreamCallback(IAsyncResult result)
at Amazon.Runtime.AmazonWebServiceClient.endOperation[T](IAsyncResult result)
at Amazon.EC2.AmazonEC2Client.DescribeInstances(DescribeInstancesRequest describeInstancesRequest)
at ...

编辑:

这个异常的内部异常是:

The remote name could not be resolved: 'ec2.sa-east-1a.amazonaws.com'

重要的是要指出,当访问区域为sa-east-1a时,它只会给我这个错误。我在us-west-2地区拥有的另一个帐户运行良好。另外,我从 web.config 中提取了凭据和区域信息

4

2 回答 2

2

简单的错误,简单的解决方案:区域是sa-east-1而不是sa-east-1a。登录时,您不应指定要使用的数据中心,而应指定区域。

于 2014-07-28T15:45:20.620 回答
1

作为对此的附录,对于到达这里但未指定数据中心的任何人。在我的情况下,使用RegionEndpoint.GetBySystemName("USEast1")vsRegionEndpoint.GetBySystemName("US-East-1")是差异制造者。

于 2016-08-23T20:18:42.080 回答