为什么在尝试获取网络接口时会出现这种情况?
com.amazonaws.services.ec2.model.AmazonEC2Exception: null (Service: AmazonEC2; Status Code: 400; Error Code: 400 Bad Request; Request ID: null)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1639)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1304)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1056)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
at com.amazonaws.services.ec2.AmazonEC2Client.doInvoke(AmazonEC2Client.java:15651)
at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:15627)
at com.amazonaws.services.ec2.AmazonEC2Client.executeDescribeInstances(AmazonEC2Client.java:7621)
at com.amazonaws.services.ec2.AmazonEC2Client.describeInstances(AmazonEC2Client.java:7597)
at com.amazonaws.services.ec2.AmazonEC2Client.describeInstances(AmazonEC2Client.java:7633)
我正在使用下面的代码。这只是一个独立的测试代码。
AmazonEC2 amazonEC2 = getEC2Client();
try {
DescribeInstancesResult result = amazonEC2.describeInstances();
for(Reservation reservation : result.getReservations()){
System.out.println(reservation.getInstances());
}
}catch (AmazonEC2Exception e){
e.printStackTrace();
}
protected static AmazonEC2 getEC2Client() {
conf = new ClientConfiguration();
conf.setConnectionTimeout(5000);
conf.setSocketTimeout(20000);
conf.setMaxErrorRetry(2);
AmazonEC2 client;
if (access_id == null && access_key == null) {
client = AmazonEC2ClientBuilder.standard().withClientConfiguration(conf).withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("https://iam.amazonaws.com", "us-east-1"))
.withCredentials(new InstanceProfileCredentialsProvider(false))
.build();
} else {
client = AmazonEC2ClientBuilder.standard().withClientConfiguration(conf).withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("https://iam.amazonaws.com","us-east-1"))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(access_id, access_key)))
.build();
}
return client;
}
我可以访问同一类中的用户列表,但不能访问与Describe *相关的内容。有人可以发表评论吗?
答案 0 :(得分:0)
尝试使用.withRegion(..)
,不要使用.withEndpointConfiguration(...)
。也许你使用了不正确的端点定义。