我正在尝试以编程方式使用EBS启动Ubuntu 12.04 LTS服务器64位。我写了以下代码:
Placement placement = new Placement("eu-west-1b");
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
.withPlacement(placement).withInstanceType("t1.micro")
.withImageId("ami-c1aaabb5").withMinCount(1).withMaxCount(1)
.withSecurityGroupIds("testGroup").withKeyName("testKey")
.withUserData(Base64.encodeBase64String(startupScript.getBytes()));
RunInstancesResult runInstances = amazonEC2.runInstances(runInstancesRequest);
List<Instance> instances = runInstances.getReservation().getInstances();
然而,我收到此错误:
AWS错误代码:InvalidAMIID.NotFound,AWS错误消息: AMI ID'ami-c1aaabb5'不存在
我在亚马逊AWS控制台中找到了实例ID,并在此网址上找到了http://cloud-images.ubuntu.com/releases/precise/release-20121001/
我做错了什么?
答案 0 :(得分:6)
我已经想通了,默认情况下请求被发送到美国弗吉尼亚州的数据中心,设置正确的终点解决了这个问题。
public AmazonEC2 createAmazonEC2() {
AmazonEC2 ec2 = new AmazonEC2Client(createAwsCredentials());
ec2.setEndpoint("https://eu-west-1.ec2.amazonaws.com");
return ec2;
}
private AWSCredentials createAwsCredentials() {
AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
return credentials;
}