gpt4 book ai didi

java - 图片id '[ami-fd9cecc7]'不存在

转载 作者:搜寻专家 更新时间:2023-11-01 02:40:37 24 4
gpt4 key购买 nike

我想使用此 Java 代码远程创建 EC2 实例:

public void testEC2ServiceInRegion() throws Exception
{

String launchInstance = launchInstance();
System.out.println("Status " + launchInstance);
}

public String launchInstance()
{
BasicAWSCredentials bawsc = new BasicAWSCredentials(
"AKIAIUY1KF4KZV3DAL21", "Onv+nq33tUkiLl1Ib2H9JtIB732QMEesh01Jl73L");

AmazonEC2 ec2 = new AmazonEC2Client(bawsc);
System.out.println("\n\nLAUNCH INSTANCE\n\n");

try
{
// Construct a RunInstancesRequest.
RunInstancesRequest request = new RunInstancesRequest();
request.setImageId("ami-fd9cecc7"); // the AMI ID, ami-fd9cecc7 is Amazon Linux AMI 2015.03 (HVM)
request.setInstanceType("t2.micro"); // instance type
request.setKeyName("desktop"); // the keypair
// request.setSubnetId("subnet-2dc0d459"); // the subnet
// ArrayList list = new ArrayList();
// list.add("sg-efcc248a"); // security group, call add() again to add more than one
// request.setSecurityGroupIds(list);
request.setMinCount(1); // minimum number of instances to be launched
request.setMaxCount(1); // maximum number of instances to be launched

// Pass the RunInstancesRequest to EC2.
RunInstancesResult result = ec2.runInstances(request);
String instanceId = result.getReservation().getInstances().get(0).getInstanceId();

// Return the first instance id in this reservation.
// So, don't launch multiple instances with this demo code.
System.out.println("Launching instance " + instanceId);
return instanceId;
} catch (Exception e)
{
// Simple exception handling by printing out error message and stack trace
System.out.println(e.getMessage());
e.printStackTrace();
return "ERROR";
}
}

但是我得到这个错误代码:

The image id '[ami-fd9cecc7]' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidAMIID.NotFound; Request ID: f85433c1-df4f-4105-bfe3-6f900eca6b70)
com.amazonaws.AmazonServiceException: The image id '[ami-fd9cecc7]' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidAMIID.NotFound; Request ID: f85433c1-df4f-4105-bfe3-6f900eca6b70)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1275)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:873)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:576)
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:362)

你能给我一些解决方案来修复这段代码吗?或者有其他选择吗?

你能推荐一些我可以使用的有效解决方案吗?

最佳答案

AMI ami-fd9cecc7 存在于悉尼 (ap-southeast-2) 区域。

当您执行代码时,请确保您在悉尼 (ap-southeast-2) 区域运行它。默认情况下,它可能在弗吉尼亚 (us-east-1) 运行。您可以通过代码更改或配置更改来指定区域。

如果您希望代码在弗吉尼亚州(或悉尼以外的任何地区)执行,则需要从该地区找到不同的 AMI 以用作 EC2 实例的基础镜像。

关于java - 图片id '[ami-fd9cecc7]'不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251041/

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