Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InvalidAMIID.NotFound, AWS Error Message: The AMI ID 'ami-c1aaabb5' does not exist

I'm trying to launch a Ubuntu 12.04 LTS Server 64 bit, with EBS, programmatically. I've written the following code:

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();

However, I get this error:

AWS Error Code: InvalidAMIID.NotFound, AWS Error Message: The AMI ID 'ami-c1aaabb5' does not exist

I've found that instance Id in Amazon AWS console and also at this URL: http://cloud-images.ubuntu.com/releases/precise/release-20121001/

What am I doing wrong?

like image 757
stivlo Avatar asked Nov 24 '12 16:11

stivlo


1 Answers

I've figured out, by default requests are sent to US Virginia data centre, setting the correct end point solved the problem.

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;
}
like image 168
stivlo Avatar answered Sep 28 '22 14:09

stivlo