1 00:00:06,810 --> 00:00:08,500 - Now let's take a look at a demo 2 00:00:08,500 --> 00:00:11,283 of querying the instance metadata service. 3 00:00:12,350 --> 00:00:14,460 Okay, so I'm at my terminal 4 00:00:14,460 --> 00:00:19,460 and I'm going to shell back 5 00:00:19,640 --> 00:00:21,490 into the instance 6 00:00:21,490 --> 00:00:23,300 that we launched in, 7 00:00:23,300 --> 00:00:24,633 shelled into earlier. 8 00:00:26,010 --> 00:00:26,843 There we go. 9 00:00:26,843 --> 00:00:31,130 So now we have a shell into our Amazon Linux instance. 10 00:00:31,130 --> 00:00:33,960 Now the instance metadata service is available 11 00:00:33,960 --> 00:00:36,400 at a very particular URL, 12 00:00:36,400 --> 00:00:40,760 so we can visit that by doing a curl 13 00:00:40,760 --> 00:00:42,938 to http 14 00:00:42,938 --> 00:00:44,660 one six nine 15 00:00:44,660 --> 00:00:48,830 dot two five four dot one six nine dot two five four 16 00:00:48,830 --> 00:00:51,286 slash latest slash 17 00:00:51,286 --> 00:00:54,260 meta dash data 18 00:00:54,260 --> 00:00:59,260 and by curling that we will get a list of other resources, 19 00:00:59,807 --> 00:01:04,260 different pieces of information that we can retrieve. 20 00:01:04,260 --> 00:01:08,761 And so again, this particular URL is only available 21 00:01:08,761 --> 00:01:11,480 from within an instance. 22 00:01:11,480 --> 00:01:14,640 And so I can only use this from within an instance 23 00:01:14,640 --> 00:01:18,935 to gain information about this one instance. 24 00:01:18,935 --> 00:01:23,580 From this instance I cannot gain information about 25 00:01:23,580 --> 00:01:27,270 other instances using instance metadata. 26 00:01:27,270 --> 00:01:29,080 And so for example, let's try, 27 00:01:29,080 --> 00:01:32,420 let's replay that and then we can go with the first one, 28 00:01:32,420 --> 00:01:36,030 all of these would then just be additions to that URL. 29 00:01:36,030 --> 00:01:40,590 So we could say, meta dash data slash ami id 30 00:01:42,920 --> 00:01:47,140 and it would give us back the machine image id 31 00:01:47,140 --> 00:01:50,180 that is currently in use on this instance. 32 00:01:50,180 --> 00:01:53,068 We could do the same thing with something like, 33 00:01:53,068 --> 00:01:57,593 host name, and you'll see here is the host name. 34 00:01:58,460 --> 00:02:02,743 We could go with instance id as well. 35 00:02:03,770 --> 00:02:06,763 Let's try instance id, 36 00:02:07,910 --> 00:02:09,940 and there you go, there is the instance id. 37 00:02:09,940 --> 00:02:13,300 And notice it's returned with as plain text, 38 00:02:13,300 --> 00:02:17,352 and so we can use the instance metadata service 39 00:02:17,352 --> 00:02:22,352 to right automated scripts, CLI scripts, 40 00:02:22,760 --> 00:02:27,430 that can be used to boot trap this instance on boot. 41 00:02:27,430 --> 00:02:29,320 So we could do something like this, 42 00:02:29,320 --> 00:02:34,320 we could say, instance id equals 43 00:02:34,819 --> 00:02:37,182 and we could copy 44 00:02:37,182 --> 00:02:39,310 that URL 45 00:02:40,310 --> 00:02:44,064 and paste it here 46 00:02:44,064 --> 00:02:47,020 and by playing that 47 00:02:47,020 --> 00:02:51,310 and now we can echo the instance id 48 00:02:51,310 --> 00:02:52,143 and there you go. 49 00:02:52,143 --> 00:02:53,860 So now we can do things like that, 50 00:02:53,860 --> 00:02:57,920 we can capture things in environment variables 51 00:02:57,920 --> 00:03:00,453 and use those in our scripts. 52 00:03:01,520 --> 00:03:04,380 So there's a lot of information here. 53 00:03:04,380 --> 00:03:06,720 There's more information about the network for example. 54 00:03:06,720 --> 00:03:11,720 Let's take a look here at the network 55 00:03:12,770 --> 00:03:14,860 and you'll see there are, 56 00:03:14,860 --> 00:03:17,010 there's another level to that, 57 00:03:17,010 --> 00:03:19,654 so we have to go network interfaces 58 00:03:19,654 --> 00:03:22,940 and we keep on going, right, 59 00:03:22,940 --> 00:03:24,740 it sometimes it keeps going 60 00:03:24,740 --> 00:03:27,770 until finally you reach some information. 61 00:03:27,770 --> 00:03:29,240 So there we go, now we have information 62 00:03:29,240 --> 00:03:30,638 about the mac address. 63 00:03:30,638 --> 00:03:35,410 And we could take a look at placement, 64 00:03:35,410 --> 00:03:37,330 I believe placement would show us, 65 00:03:37,330 --> 00:03:38,833 let's see what that shows us. 66 00:03:41,849 --> 00:03:45,570 So then placement availability zone, right, 67 00:03:45,570 --> 00:03:48,573 so let's copy that and then try that one. 68 00:03:48,573 --> 00:03:51,820 And there you go, now it's showing us the availability zone. 69 00:03:51,820 --> 00:03:55,380 So we could capture that, say, in a script 70 00:03:55,380 --> 00:03:57,610 and then use that information somewhere else 71 00:03:57,610 --> 00:04:00,444 in that script, right, so we may want to, 72 00:04:00,444 --> 00:04:05,304 for example, capture the instance id 73 00:04:05,304 --> 00:04:09,050 and the particular availability zone 74 00:04:09,050 --> 00:04:12,541 and then use the availability zone to determine which 75 00:04:12,541 --> 00:04:15,498 maybe if there's an EBS volume available, 76 00:04:15,498 --> 00:04:20,100 and then use the instance id to as a call 77 00:04:20,100 --> 00:04:25,100 to attach an EBS volume, or to update routing tables. 78 00:04:26,210 --> 00:04:29,661 We can use information about the network to, say, update, 79 00:04:29,661 --> 00:04:33,019 automatically update route tables, or firewall rules, 80 00:04:33,019 --> 00:04:35,690 or things like that, right. 81 00:04:35,690 --> 00:04:39,937 So there, again, lot of information available in this 82 00:04:40,960 --> 00:04:43,674 particular list of possibilities to run 83 00:04:43,674 --> 00:04:48,674 with the instance metadata service and the primary use case 84 00:04:49,778 --> 00:04:53,730 for the instance metadata service is to automate 85 00:04:55,430 --> 00:04:57,390 the bootstrapping of this machine. 86 00:04:57,390 --> 00:05:00,428 So this machine can, you know, boot and then say 87 00:05:00,428 --> 00:05:04,066 all right who am I, and where am I, 88 00:05:04,066 --> 00:05:07,130 and what am I supposed to be doing, right. 89 00:05:07,130 --> 00:05:09,850 So we can use those scripts to pull the instance id 90 00:05:09,850 --> 00:05:12,312 and any other information that we need about this instance 91 00:05:12,312 --> 00:05:16,313 in order to then go on and configure other things.