1 00:00:00,170 --> 00:00:02,370 ‫Okay so a theory lecture 2 00:00:02,370 --> 00:00:05,620 ‫around how to integrate ECS with X-Ray 3 00:00:05,620 --> 00:00:08,320 ‫and the three options you're going to have. 4 00:00:08,320 --> 00:00:10,320 ‫So first, you have an ECS Cluster 5 00:00:10,320 --> 00:00:12,620 ‫and one way to run the X-Ray Daemon 6 00:00:12,620 --> 00:00:15,470 ‫is to use the container as a Daemon itself. 7 00:00:15,470 --> 00:00:16,810 ‫So, what does that mean? 8 00:00:16,810 --> 00:00:18,670 ‫That means we have our two EC2 instance. 9 00:00:18,670 --> 00:00:20,170 ‫For example, in our ECS cluster, 10 00:00:20,170 --> 00:00:23,440 ‫and remember we manage those EC2 instances 11 00:00:23,440 --> 00:00:26,420 ‫and so we're going to run a Daemon task, 12 00:00:26,420 --> 00:00:28,810 ‫a Daemon container, of the X-Ray Daemon. 13 00:00:28,810 --> 00:00:31,480 ‫So there's two ice to the word Daemon in here. 14 00:00:31,480 --> 00:00:33,390 ‫That means that the X-Ray Daemon Container 15 00:00:33,390 --> 00:00:36,430 ‫will be running on every single EC2 instances. 16 00:00:36,430 --> 00:00:39,480 ‫If you have 10 EC2 instances in your ECS cluster, 17 00:00:39,480 --> 00:00:43,140 ‫then you will have 10 containers, one on each EC2 instance, 18 00:00:43,140 --> 00:00:44,900 ‫running as a Daemon Container. 19 00:00:44,900 --> 00:00:47,070 ‫Okay, so that means that the X-Ray agent 20 00:00:47,070 --> 00:00:50,330 ‫is now running on all these EC2 instances. 21 00:00:50,330 --> 00:00:52,430 ‫And so you can launch your App Containers 22 00:00:52,430 --> 00:00:55,850 ‫on the EC2 instances, and after matting them correctly 23 00:00:55,850 --> 00:00:59,110 ‫from the networking standpoint to hit the X-Ray Daemon 24 00:00:59,110 --> 00:01:00,410 ‫with a UDP port. 25 00:01:00,410 --> 00:01:02,100 ‫Then you can run all your applications. 26 00:01:02,100 --> 00:01:03,500 ‫So, in this case, you will just 27 00:01:03,500 --> 00:01:07,570 ‫have one X-Ray Daemon Container per EC2 instance. 28 00:01:07,570 --> 00:01:10,960 ‫Now, the second pattern to run X-Ray in your ECS cluster 29 00:01:10,960 --> 00:01:13,480 ‫is called the Side Car pattern. 30 00:01:13,480 --> 00:01:15,010 ‫So what does it mean, Side Car pattern? 31 00:01:15,010 --> 00:01:17,200 ‫That means you still have your EC2 instances, 32 00:01:17,200 --> 00:01:20,380 ‫but now you're going to run one X-Ray Daemon Container 33 00:01:20,380 --> 00:01:23,090 ‫alongside each application container, 34 00:01:23,090 --> 00:01:26,390 ‫and they will connect from a networking stand point. 35 00:01:26,390 --> 00:01:27,830 ‫So this is why it's called a Side Car, 36 00:01:27,830 --> 00:01:31,760 ‫it's because the X-Ray Daemon now runs side-to-side 37 00:01:31,760 --> 00:01:34,570 ‫as our application container, and it's a Side Dar. 38 00:01:34,570 --> 00:01:37,330 ‫So, if we look at this now, we have one Side Car 39 00:01:37,330 --> 00:01:38,500 ‫per App Container. 40 00:01:38,500 --> 00:01:42,050 ‫So, if you have 20 App Containers under one EC2 instance 41 00:01:42,050 --> 00:01:44,830 ‫then we'll have 20 X-Ray Side Car. 42 00:01:44,830 --> 00:01:46,260 ‫So, this is the way it works, 43 00:01:46,260 --> 00:01:48,580 ‫from a Side Car pattern. 44 00:01:48,580 --> 00:01:51,780 ‫Now, Fargate Clusters, we don't have control 45 00:01:51,780 --> 00:01:54,520 ‫over the EC2 instances, it's just an ECS Cluster 46 00:01:54,520 --> 00:01:56,010 ‫that we don't have any control 47 00:01:56,010 --> 00:01:57,870 ‫over the underlying instances. 48 00:01:57,870 --> 00:02:00,840 ‫So, we can not use the X-Ray Daemon Container, 49 00:02:00,840 --> 00:02:02,800 ‫we also have to use the X-Ray Container 50 00:02:02,800 --> 00:02:04,230 ‫as a Side Car pattern. 51 00:02:04,230 --> 00:02:06,070 ‫So, if you want to launch a Fargate task, 52 00:02:06,070 --> 00:02:09,070 ‫it would be the App Container and the X-Ray Side Car, 53 00:02:09,070 --> 00:02:10,620 ‫here and there. 54 00:02:10,620 --> 00:02:12,150 ‫So, that gives you the three options 55 00:02:12,150 --> 00:02:13,710 ‫to run ECS and X-Ray and hopefully 56 00:02:13,710 --> 00:02:15,310 ‫that makes it a little bit clear 57 00:02:15,310 --> 00:02:16,950 ‫as to how you could do it. 58 00:02:16,950 --> 00:02:18,340 ‫Now, I'm going to still show you 59 00:02:18,340 --> 00:02:21,350 ‫an Example Task Definition, though we're not going to run it 60 00:02:21,350 --> 00:02:23,310 ‫because we need to build all the images, 61 00:02:23,310 --> 00:02:24,730 ‫and that would be quite complicated. 62 00:02:24,730 --> 00:02:27,100 ‫But so here's something from the documentation. 63 00:02:27,100 --> 00:02:28,420 ‫And what do we see here? 64 00:02:28,420 --> 00:02:30,220 ‫Well, the first thing we should look at 65 00:02:30,220 --> 00:02:32,047 ‫is that the X-Ray Daemon is going to be running, 66 00:02:32,047 --> 00:02:35,110 ‫that's the first part of this task definition. 67 00:02:35,110 --> 00:02:37,110 ‫And in terms of port mappings, 68 00:02:37,110 --> 00:02:42,110 ‫the container port 2000 is mapped onto the instance. 69 00:02:43,080 --> 00:02:45,050 ‫And the protocol is UDP. 70 00:02:45,050 --> 00:02:47,130 ‫So, remember this container port 2000, 71 00:02:47,130 --> 00:02:48,750 ‫and the protocol is UDP. 72 00:02:48,750 --> 00:02:50,770 ‫And so once the X-Ray Daemon is running, 73 00:02:50,770 --> 00:02:54,080 ‫this is a Side Car pattern, here we have our application. 74 00:02:54,080 --> 00:02:56,300 ‫It's called Scorekeep Api for this case. 75 00:02:56,300 --> 00:02:58,140 ‫And so the second thing we need to look at, 76 00:02:58,140 --> 00:03:03,140 ‫is this environment variable called AWS X-Ray Daemon Address 77 00:03:04,030 --> 00:03:06,650 ‫and this is an environment variable you need to set, 78 00:03:06,650 --> 00:03:09,450 ‫because that's how the X-Ray Daemon will know 79 00:03:09,450 --> 00:03:10,520 ‫where to find 80 00:03:12,220 --> 00:03:13,530 ‫that's how the X-Ray as the case 81 00:03:13,530 --> 00:03:16,600 ‫sorry, will know how to find the X-Ray Daemon. 82 00:03:16,600 --> 00:03:19,850 ‫So, the value of this, is X-Ray Daemon port 2000, 83 00:03:19,850 --> 00:03:23,540 ‫and this 2000 is coming from the 2000 from above, 84 00:03:23,540 --> 00:03:25,670 ‫and then finally, the last thing you need to do, 85 00:03:25,670 --> 00:03:27,830 ‫is link these two containers together 86 00:03:27,830 --> 00:03:29,530 ‫from a networking stand point. 87 00:03:29,530 --> 00:03:32,370 ‫So that's why it says links X-Ray Daemon, 88 00:03:32,370 --> 00:03:33,790 ‫and this is how it's able to resolve 89 00:03:33,790 --> 00:03:36,880 ‫this host name X-Ray Daemon to this container right here. 90 00:03:36,880 --> 00:03:38,400 ‫So, it could be a little bit complicated, 91 00:03:38,400 --> 00:03:39,980 ‫especially if you're new with ECS. 92 00:03:39,980 --> 00:03:42,610 ‫But remember, the take away from this slide 93 00:03:42,610 --> 00:03:44,830 ‫is that you need to map the Container Port 94 00:03:44,830 --> 00:03:47,170 ‫of the X-Ray Daemon to 2000 UDP. 95 00:03:47,170 --> 00:03:49,170 ‫Then, you need to set an environment variable, 96 00:03:49,170 --> 00:03:50,350 ‫called X-Ray Daemon address. 97 00:03:50,350 --> 00:03:52,740 ‫And finally, you need to link these two containers 98 00:03:52,740 --> 00:03:54,531 ‫from a networking standpoint. 99 00:03:54,531 --> 00:03:56,910 ‫So, I hope that helps you to understand precisely 100 00:03:56,910 --> 00:03:58,380 ‫how to run X-Ray with ECS. 101 00:03:58,380 --> 00:04:00,500 ‫I know that question has come up on the exam several times 102 00:04:00,500 --> 00:04:01,450 ‫with several students. 103 00:04:01,450 --> 00:04:03,090 ‫So I thought it would be great for you 104 00:04:03,090 --> 00:04:05,580 ‫to get a little bit more insights deeper inside 105 00:04:05,580 --> 00:04:06,970 ‫to how these things work. 106 00:04:06,970 --> 00:04:08,360 ‫All right, I hope that was helpful, 107 00:04:08,360 --> 00:04:10,310 ‫and I will see you in the next lecture.