我一直致力于亚马逊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.
STACK TRACE:
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
中提取了Credential和Region信息答案 0 :(得分:2)
简单错误,简单解决方案:该区域 sa-east-1 而不是 sa-east-1a 。登录时,您不应指定要使用的数据中心,而只是指定区域。
答案 1 :(得分:1)
作为附录,对于到达此处未指定数据中心的任何人。在我的情况下,使用RegionEndpoint.GetBySystemName("USEast1")
vs RegionEndpoint.GetBySystemName("US-East-1")
是差异制造者。