Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ec2-describe-instance-status Client.InvalidInstanceID.NotFound but I KNOW instance exists

Tags:

I have setup a few of the amazon AWS CLI tools (EC2, Auto Scaling, MOnitoring and ELB). The tools are setup correctly and work perfectly. My environment vars are all set, the relevant ones to this Q being:

export EC2_REGION=eu-west-1 export EC2_URL=https://ec2.$EC2_REGION.amazonaws.com export AWS_ELB_URL=https://elasticloadbalancing.$EC2_REGION.amazonaws.com 

When I run ec2-describe-instance-status i-XXXXXXXX for ANY of my instances, I get:

Client.InvalidInstanceID.NotFound: The instance ID 'i-XXXXXXXX' does not exist 

I KNOW the instance ID exists, I copied it out of the AWS web console, and it is in the eu-west-1 region, and my env vars are set to this region.

For the life of me I can't figure out why it will not find my instances. Is there anything glaringly obvious that I am doing incorrectly?

UPDATE: recreating x509 cert/pk solved this... for some reason.

like image 845
BoomShaka Avatar asked Apr 12 '13 11:04

BoomShaka


People also ask

How do I check my EC2 instance Status?

You can view status checks by using the AWS Management Console. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Instances. On the Instances page, the Status check column lists the operational status of each instance.

How do you describe EC2 Instances?

An Amazon EC2 instance is a virtual server in Amazon's Elastic Compute Cloud (EC2) for running applications on the Amazon Web Services (AWS) infrastructure.

How do I know if I have an instance IMDSv2?

If you want to determine it from the EC2 instance, you can just try sending a request to http://169.254.169.254/ and see what the status code is. The 401 status code means Unauthorized. This server does not require IMDSv2 ( HttpTokens is optional ).

How can I tell who stopped an instance?

Open the CloudTrail console. In the navigation pane, choose Event history. In the Lookup attributes dropdown menu, select Event name. For Enter an event name, enter StopInstances if your instance was stopped.


2 Answers

I had the same problem. It was because I wasn't defining a region for my commands. I assumed it would list all instances across all regions but it defaults to us-west-1 and I don't have any instances there.

To describe my machines in Ireland I use the following:

ec2-describe-instances --region eu-west-1
NB: I'm defining my AWS access key and secret elsewhere.

To avoid this problem going forward, I've now set my region via an environment variable on my linux and windows machines: EC2_URL=https://ec2.eu-west-1.amazonaws.com so that I don't have to be explicit on the command line.

Update May 2014 You can also set the region by adding the following lines to the ~/.aws/config file in your home folder (not tested on Windows). This is my preferred method now, especially on my VM's and containers:

[default] region = eu-west-1 

For more information see the offical docs here.

Update May 2021 Since I work across so many regions now I use Implicit and ephemeral environment variables to define my region for that command and NOT have a default in my .aws/config which can be dangerous. This also makes bash scripting easier as I can define it for the whole script/utility. It's a tiny bit more typing but far safer, more flexible and transparent e.g.:

AWS_DEFAULT_REGION=eu-central-1 aws ec2 describe-instances  # or for a script/utility AWS_DEFAULT_REGION=us-east-1 ./tagInstances.sh 
like image 152
Jujhar Singh Avatar answered Sep 20 '22 18:09

Jujhar Singh


Weird issue - as usual when encountering something weird in software development, one should first question the assumptions:

I KNOW the instance ID exists, I copied it out of the AWS web console, and it is in the eu-west-1 region, and my env vars are set to this region.

So the instance ID stems from a different environment than the one you want to use it in - I would try to derive the instance ID via the same environment instead, i.e.:

ec2-describe-instances 

I venture the guess that the list won't return the instances you are expecting. This would indicate that you are either using AWS credentials that belong to another account or that these credentials do not have the required Amazon EC2 read permissions assigned via IAM policies for example.

like image 26
Steffen Opel Avatar answered Sep 22 '22 18:09

Steffen Opel