1 00:00:06,677 --> 00:00:08,395 - Alright so now let's run through a demo 2 00:00:08,395 --> 00:00:12,573 of the instance metadata service in Amazon EC2. 3 00:00:12,573 --> 00:00:15,596 I'm going to, from my terminal, I'm gonna SSH 4 00:00:15,596 --> 00:00:19,263 back into a machine that we created earlier. 5 00:00:22,269 --> 00:00:26,589 Now that I've got a shell into my EC2 instance, 6 00:00:26,589 --> 00:00:30,299 we can see here I'm going to just run curl 7 00:00:30,299 --> 00:00:33,232 against the instance metadata ip address 8 00:00:33,232 --> 00:00:37,399 which is 169.254.169.254/latest/meta-data. 9 00:00:45,081 --> 00:00:48,160 What I get is a menu of all of the things 10 00:00:48,160 --> 00:00:52,029 that are available from that particular service. 11 00:00:52,029 --> 00:00:54,256 You can see here, starting at the top, 12 00:00:54,256 --> 00:00:57,962 if I want to get the ami id of the machine that's running, 13 00:00:57,962 --> 00:01:01,212 I can replay that and just type ami-id. 14 00:01:03,313 --> 00:01:04,396 There you go. 15 00:01:06,893 --> 00:01:10,762 You can see that it gives it to us there. 16 00:01:10,762 --> 00:01:13,584 If we wanted to script that. 17 00:01:13,584 --> 00:01:15,869 Let's actually try one of the other ones. 18 00:01:15,869 --> 00:01:18,348 Like the instance id is actually one that's 19 00:01:18,348 --> 00:01:20,718 generally most useful for doing automated 20 00:01:20,718 --> 00:01:23,328 scripting types of things. 21 00:01:23,328 --> 00:01:27,328 So let's try that again and use the instance id. 22 00:01:28,330 --> 00:01:29,933 There we go. 23 00:01:29,933 --> 00:01:32,228 You can see it gives us back the instance id. 24 00:01:32,228 --> 00:01:34,455 This is how we might actually leverage that. 25 00:01:34,455 --> 00:01:38,122 We can say something like export instance id 26 00:01:44,880 --> 00:01:47,380 equals, I'm gonna copy this... 27 00:01:52,620 --> 00:01:55,836 Put that in dollar sign parenthesis, 28 00:01:55,836 --> 00:01:59,753 hit return and now if I say echo $ instance id, 29 00:02:04,985 --> 00:02:06,569 there we go. 30 00:02:06,569 --> 00:02:09,507 Now we have that instance id listed, or exported, 31 00:02:09,507 --> 00:02:11,254 to an environment variable. 32 00:02:11,254 --> 00:02:14,930 From there we can have different types of shell scripts 33 00:02:14,930 --> 00:02:18,108 leverage those environment variables for boot strapping 34 00:02:18,108 --> 00:02:21,202 this instance and getting it up and running. 35 00:02:21,202 --> 00:02:24,358 Perhaps this instance needs to grab its instance id 36 00:02:24,358 --> 00:02:26,124 and report back to some kind 37 00:02:26,124 --> 00:02:28,054 of configuration management tool, 38 00:02:28,054 --> 00:02:32,691 or some kind of monitoring tool like Nagios or the like. 39 00:02:32,691 --> 00:02:36,858 We can also do the very same thing and use its local ipv4. 40 00:02:37,855 --> 00:02:42,022 Let's do that; let's grab the local, private ip address. 41 00:02:44,940 --> 00:02:47,273 Local-ipv4 and there you go. 42 00:02:49,693 --> 00:02:51,152 There's the private ip address 43 00:02:51,152 --> 00:02:53,061 of this particular instance. 44 00:02:53,061 --> 00:02:55,183 You can see the instance metadata service 45 00:02:55,183 --> 00:02:58,524 is a really powerful way for our instances 46 00:02:58,524 --> 00:03:01,616 to get information about themselves. 47 00:03:01,616 --> 00:03:04,965 Again, I can't reach this ip from anywhere else. 48 00:03:04,965 --> 00:03:08,122 I had a vc2 and I cannot use this ip 49 00:03:08,122 --> 00:03:11,253 to get information about another instance. 50 00:03:11,253 --> 00:03:14,641 It's for an instance to get information about itself. 51 00:03:14,641 --> 00:03:18,808 It's a really helpful tool to use for auto configuration. 52 00:03:19,757 --> 00:03:22,301 It will help us maintain high availability. 53 00:03:22,301 --> 00:03:24,153 It will help us create environments 54 00:03:24,153 --> 00:03:27,303 that are self-healing and automated. 55 00:03:27,303 --> 00:03:31,470 So that is the instance metadata service in Amazon EC2.