26

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.

BMW
  • 42,880
  • 12
  • 99
  • 116
BoomShaka
  • 1,571
  • 7
  • 27
  • 40

6 Answers6

46

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
Jujhar Singh
  • 3,641
  • 5
  • 29
  • 38
4

In my case, I had two sets of credentials in ~/.aws/credentials. To specify the credentials tag, use

aws ec2 describe-instances --instance-id <your-instance-id> --profile <your-profile-name> --region <your-region>

Daisuke Aramaki
  • 316
  • 3
  • 7
3

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.

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
  • Thanks for the input. Terrifyingly ec2-describe-instances (even with the region argument) outputs nothing. I've installed the latest ec2 CLI tools (as of today) and ec2-describe-regions gives VALID output. Perhaps something to do with my creds. – BoomShaka Apr 12 '13 at 11:38
  • I recreated my x509 certificate and private key. This solved the problem. It must have expired, though the one I was using WAS marked as active. Strange. – BoomShaka Apr 12 '13 at 12:07
  • @BoomShaka - I highly recommend switching to using IAM access keys only, which are much easier to use and significantly more versatile, and thus implicitly more secure; X.509 certificates are [meanwhile deprecated](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/setting_up_ec2_command_linux.html#set_aws_credentials_linux) for the EC2 Command Line Tools and hardly ever used elsewhere for quite some time already. See my answer to [How to download an EC2 X.509 certificate with an IAM User account?](http://stackoverflow.com/a/8995926/45773) for a bit more on this. – Steffen Opel Apr 12 '13 at 14:17
3

I had a similar issue and I write here the solution for anybody who can find it helpful.

I was stucked with this error during some hours.

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

Finally I found what was happening: I had my instance in a different region than the default region (US East (Northern Virginia)) and I had to update this information. By default the commands look only for instances in the default region!

It is explained in the docs, section (Optional): Set the region http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SettingUp_CommandLine.html

Miquel
  • 858
  • 11
  • 20
1

It's very simple problem. If you are getting this error

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

Then follow the steps.

  1. Check in which country region your instance is image here

Now enter root@Indian:~# aws configure

Enter

AWS Access Key ID [****************D7M2]:

AWS Secret Access Key [****************2h3r]:

Default region name [us-east-1]:

When asked for default region, Change the region to which the instances is residing. Eg: us-east-2. Then press Enter. Acutally these are the list of available Region names "RegionNames"

 "Regions": [
    {
        "RegionName": "ap-south-1",
        "Endpoint": "ec2.ap-south-1.amazonaws.com"
    },
    {
        "RegionName": "eu-west-2",
        "Endpoint": "ec2.eu-west-2.amazonaws.com"
    },
    {
        "RegionName": "eu-west-1",
        "Endpoint": "ec2.eu-west-1.amazonaws.com"
    },
    {
        "RegionName": "ap-northeast-2",
        "Endpoint": "ec2.ap-northeast-2.amazonaws.com"
    },
    {
        "RegionName": "ap-northeast-1",
        "Endpoint": "ec2.ap-northeast-1.amazonaws.com"
    },
    {
        "RegionName": "sa-east-1",
        "Endpoint": "ec2.sa-east-1.amazonaws.com"
    },
    {
        "RegionName": "ca-central-1",
        "Endpoint": "ec2.ca-central-1.amazonaws.com"
    },
    {
        "RegionName": "ap-southeast-1",
        "Endpoint": "ec2.ap-southeast-1.amazonaws.com"
    },
    {
        "RegionName": "ap-southeast-2",
        "Endpoint": "ec2.ap-southeast-2.amazonaws.com"
    },
    {
        "RegionName": "eu-central-1",
        "Endpoint": "ec2.eu-central-1.amazonaws.com"
    },
    {
        "RegionName": "us-east-1",
        "Endpoint": "ec2.us-east-1.amazonaws.com"
    },
    {
        "RegionName": "us-east-2",
        "Endpoint": "ec2.us-east-2.amazonaws.com"
    },
    {
        "RegionName": "us-west-1",
        "Endpoint": "ec2.us-west-1.amazonaws.com"
    },
    {
        "RegionName": "us-west-2",
        "Endpoint": "ec2.us-west-2.amazonaws.com"
    }
]
}

Default output format [None]:

Leave the output format blank and press Enter. Now You are Done

Now in the console just type

root@Indian-3543:~# aws ec2 describe-instance --instance-id i-06343434322t

MAKE HAPPY BE HAPPY

Regolith
  • 2,944
  • 9
  • 33
  • 50
imran
  • 39
  • 1
  • 5
0

I got this fixed by changing EC2_URL from 'https://ec2.ap-southeast-1.amazonaws.com' to 'ec2.ap-southeast-1.amazonaws.com'

Mark Khor
  • 396
  • 5
  • 7