AWS Error Message: InvalidInstanceID.NotFound

I am trying to start an Amazon EC2 cloud computer using the [startInstance][2] method using aws-sdk in Java. My code is as follows.

 public String startInstance(String instanceId) throws Exception { List<String> instanceIds = new ArrayList<String>(); instanceIds.add(instanceId); StartInstancesRequest startRequest = new StartInstancesRequest( instanceIds); startRequest.setRequestCredentials(getCredentials()); StartInstancesResult startResult = ec2.startInstances(startRequest); List<InstanceStateChange> stateChangeList = startResult .getStartingInstances(); log.trace("Starting instance '{}':", instanceId); // Wait for the instance to be started return waitForTransitionCompletion(stateChangeList, "running", instanceId); } 

When I run the above code, I get the following AWS error:

 Status Code: 400, AWS Request ID: e1bd4795-a609-44d1-9e80-43611e80006b, AWS Erro r Code: InvalidInstanceID.NotFound, AWS Error Message: The instance ID 'i-2b97ac 2f' does not exist at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpCli ent.java:538) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.ja va:283) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:168 ) at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.jav a:5208) at com.amazonaws.services.ec2.AmazonEC2Client.startInstances(AmazonEC2Cl ient.java:2426) 
+8
source share
4 answers

AWS error message: instance id 'i-2b97ac2f' does not exist

You will need to accept the AWS response if it is not listed here, i.e. instance does not exist;)

But seriously: presumably you have already verified that you are actually launching an instance with this ID in your account? Then this is most likely due to targeting the wrong API endpoint, since the instance ID is valid only in a specific region (if not specified, the default region is "us-east-1", see below).

In this case, you need to specify the actual region of the instance using the setEndpoint () of the AmazonEC2Client method within the visible global variable ec2 before calling startInstances () .

There are several examples regarding Regions with the AWS SDK , and all currently available AWS endpoint URLs are listed in Regions and endpoints , in particular Amazon Elastic Compute Cloud (EC2) is used by default for 'us-east-1' :

If you simply specify a common endpoint (ec2.amazonaws.com), Amazon EC2 routes your request to the us-east-1 endpoint.

+15
source

We start the service (Qubole), which often spawns, and then tags (and in some cases terminates) AWS instances immediately.

We found that Amazon would require from time to time that instanceid be invalid, although it just created it. Retrying several times with some sleep time thrown usually solves the problem. Even the total repetition interval of 15 years was insufficient in rare cases.

This experience comes from the area of ​​useast. We do not make air calls to different regions - so this is not an explanation. This is most likely the infamous possible sequence at work - where AWS cannot provide post-read consistency for these api calls.

+11
source

I am using AWS ruby ​​api, and I noticed the same problem when creating an AMI image, and its status is pending when I look in the AWS console, but after a while the image is available for use.

Here is my script

 image = ec2.images.create(:name => image_name, :instance_id => ami_id, :description => desc) sleep 5 while image.state != :available 

I sleep about 5 seconds for the image to be available, but I get the error message "AWS error message: InvalidInstanceID.NotFound". This is fine during my testing, but most of the time it seems to fail during continuous integration builds.

0
source

InvalidInstanceID.NotFound means that the specified instance does not exist.

  • Make sure you specify the region where the instance is located if it is not in the default region.
  • This error may occur because the identifier of a newly created instance is not distributed across the system. For more information, see Possible Consistency .
0
source

Source: https://habr.com/ru/post/906642/


All Articles