亚马逊AWS:无法登录
本文关键字:登录 AWS 亚马逊 | 更新日期: 2023-09-27 18:15:27
我一直在做一个amazon 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
简单的错误,简单的解决方法:区域是sa-east-1而不是sa-east-1a。登录时,不应该指定要使用哪个数据中心,而应该指定区域。
作为本文的附录,给那些没有指定数据中心的人。在我的案例中,使用RegionEndpoint.GetBySystemName("USEast1")
和RegionEndpoint.GetBySystemName("US-East-1")
是差异制造者。