我一直在做一个亚马逊 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 中提取了凭据和区域信息