5

我正在尝试以编程方式启动带有 EBS 的 Ubuntu 12.04 LTS Server 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' 不存在

我在 Amazon AWS 控制台和以下 URL 中找到了该实例 ID:http: //cloud-images.ubuntu.com/releases/precise/release-20121001/

我究竟做错了什么?

4

1 回答 1

7

我发现,默认情况下,请求被发送到美国弗吉尼亚数据中心,设置正确的端点解决了这个问题。

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;
}
于 2012-11-24T17:01:39.293 回答