java 错误信息:AMI ID“ami-c1 aaabb 5”不存在

jk9hmnmh  于 2023-02-18  发布在  Java
关注(0)|答案(1)|浏览(119)

我正在尝试以编程方式启动一个Ubuntu 12.04 LTS服务器64位,带有EBS。我编写了以下代码:

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错误代码:错误信息:AMI ID "ami-c1aaabb5"不存在
我在Amazon AWS控制台和以下URL中找到了该示例ID:http://cloud-images.ubuntu.com/releases/precise/release-20121001/
我做错了什么?我怎么能做对呢?

avkwfej4

avkwfej41#

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

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;
}

相关问题