AWS Tutorial 06 - Getting Your Instance ID and Why It Matters

Sep 7, 2016

In the world of AWS, your server is referred to as an EC2 instance and it is uniquely identified by a “instance-id”, a unique alpha numeric identifier that you can use to reference your server. Your instance id can be used in all kinds of ways including:

log files

database records

security analysis

In my case I’m using AWS to crawl different websites and one of the things I’m encountering is that it is very, very hard to know what AWS instance ty;e is the best value. Specifically do I optimize for more memory, more CPU, more disk and so on. One thing you can do is push your instance id right down to the unit of work. In my case that’s a database transaction so I can do things like this:

So if these 3 different instance types, and they were all started at the same time, I can see that, well, they’re all doing roughly the same amount of work so maybe the instance type doesn’t matter all that much and I should just buy the cheapest.

Here’s how you fetch the instance id – and its brilliantly simple – you can just use wget or curl. Here’s an example:

curl http://169.254.169.254/latest/meta-data/instance-id

And that will return back a chunk of information which is just the instance id. Want your region instead then just use: