- Alright so now let's run through a demo
of the instance metadata service in Amazon EC2.
I'm going to, from my terminal, I'm gonna SSH
back into a machine that we created earlier.
Now that I've got a shell into my EC2 instance,
we can see here I'm going to just run curl
against the instance metadata ip address
which is 169.254.169.254/latest/meta-data.
What I get is a menu of all of the things
that are available from that particular service.
You can see here, starting at the top,
if I want to get the ami id of the machine that's running,
I can replay that and just type ami-id.
There you go.
You can see that it gives it to us there.
If we wanted to script that.
Let's actually try one of the other ones.
Like the instance id is actually one that's
generally most useful for doing automated
scripting types of things.
So let's try that again and use the instance id.
There we go.
You can see it gives us back the instance id.
This is how we might actually leverage that.
We can say something like export instance id
equals, I'm gonna copy this...
Put that in dollar sign parenthesis,
hit return and now if I say echo $ instance id,
there we go.
Now we have that instance id listed, or exported,
to an environment variable.
From there we can have different types of shell scripts
leverage those environment variables for boot strapping
this instance and getting it up and running.
Perhaps this instance needs to grab its instance id
and report back to some kind
of configuration management tool,
or some kind of monitoring tool like Nagios or the like.
We can also do the very same thing and use its local ipv4.
Let's do that; let's grab the local, private ip address.
Local-ipv4 and there you go.
There's the private ip address
of this particular instance.
You can see the instance metadata service
is a really powerful way for our instances
to get information about themselves.
Again, I can't reach this ip from anywhere else.
I had a vc2 and I cannot use this ip
to get information about another instance.
It's for an instance to get information about itself.
It's a really helpful tool to use for auto configuration.
It will help us maintain high availability.
It will help us create environments
that are self-healing and automated.
So that is the instance metadata service in Amazon EC2.