gpt4 book ai didi

java - InvalidAMIID.NotFound,AWS 错误消息 : The AMI ID 'ami-c1aaabb5' does not exist

转载 作者:搜寻专家 更新时间:2023-10-31 19:56:37 26 4
gpt4 key购买 nike

我正在尝试以编程方式启动带有 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 Error Code: InvalidAMIID.NotFound, AWS Error Message: The AMI ID 'ami-c1aaabb5' does not exist

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

我做错了什么?

最佳答案

我发现,默认情况下请求会发送到美国弗吉尼亚数据中心,设置正确的终点可以解决问题。

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

关于java - InvalidAMIID.NotFound,AWS 错误消息 : The AMI ID 'ami-c1aaabb5' does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13543071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com