1 00:00:00,000 --> 00:00:01,280 ‫So now let's talk about 2 00:00:01,280 --> 00:00:03,300 ‫what is an auto scaling group. 3 00:00:03,300 --> 00:00:05,940 ‫So when we deploy a website or an application, 4 00:00:05,940 --> 00:00:08,140 ‫the load can change over time because we may have 5 00:00:08,140 --> 00:00:11,130 ‫more users visiting our websites over time. 6 00:00:11,130 --> 00:00:13,260 ‫And we've seen that in the cloud, in AWS, 7 00:00:13,260 --> 00:00:15,200 ‫it's possible for us to create 8 00:00:15,200 --> 00:00:17,960 ‫and also get rid of servers very quickly 9 00:00:17,960 --> 00:00:20,543 ‫with the EC2 instance creation API call. 10 00:00:21,430 --> 00:00:23,070 ‫So, if you wanna automate this, 11 00:00:23,070 --> 00:00:25,160 ‫we can create an auto-scaling group. 12 00:00:25,160 --> 00:00:28,200 ‫So the goal of the ASG is to scale out, 13 00:00:28,200 --> 00:00:30,640 ‫that means add EC2 instances and you need to remember this, 14 00:00:30,640 --> 00:00:33,680 ‫scale out to match an increased load 15 00:00:33,680 --> 00:00:37,210 ‫or to scale in that means removing EC2 instances 16 00:00:37,210 --> 00:00:39,520 ‫to match a decreased load. 17 00:00:39,520 --> 00:00:41,310 ‫And so therefore the size of our ASG 18 00:00:41,310 --> 00:00:43,240 ‫is going to vary over time. 19 00:00:43,240 --> 00:00:45,010 ‫Overall, we can also define parameters 20 00:00:45,010 --> 00:00:46,380 ‫to ensure we'll have a minimum 21 00:00:46,380 --> 00:00:49,890 ‫and a maximum number of EC2 instances running at any time 22 00:00:49,890 --> 00:00:51,840 ‫in our ASG. 23 00:00:51,840 --> 00:00:53,680 ‫ASG also have the superpower 24 00:00:53,680 --> 00:00:56,920 ‫that if you are pairing it with a load balancer, 25 00:00:56,920 --> 00:01:00,230 ‫then any EC2 instances as part of the ASG 26 00:01:00,230 --> 00:01:02,290 ‫will be linked to the load balancer. 27 00:01:02,290 --> 00:01:03,720 ‫Another superpower is that 28 00:01:03,720 --> 00:01:07,430 ‫if one instance is deemed unhealthy, it is terminated 29 00:01:07,430 --> 00:01:10,750 ‫and a new EC2 instance is created to replace it. 30 00:01:10,750 --> 00:01:12,860 ‫So, auto scaling groups are free 31 00:01:12,860 --> 00:01:13,960 ‫and you're only going to pay 32 00:01:13,960 --> 00:01:16,040 ‫for whatever resources are created underneath 33 00:01:16,040 --> 00:01:18,460 ‫such as your EC2 instances. 34 00:01:18,460 --> 00:01:21,150 ‫So let's see how an ESG works in AWS. 35 00:01:21,150 --> 00:01:23,540 ‫So we set a minimum capacity, 36 00:01:23,540 --> 00:01:27,330 ‫which is how many instances you want at minimum in your ASG. 37 00:01:27,330 --> 00:01:28,650 ‫For example, two. 38 00:01:28,650 --> 00:01:30,310 ‫Then you set a desired capacity, 39 00:01:30,310 --> 00:01:32,730 ‫which is how many instances you want in your ASG, 40 00:01:32,730 --> 00:01:35,770 ‫for example, four and then you set a maximum capacity 41 00:01:35,770 --> 00:01:37,570 ‫which is how many instances 42 00:01:37,570 --> 00:01:40,410 ‫at a maximum do I want in my ASG. 43 00:01:40,410 --> 00:01:43,780 ‫And then that means that if you move the desire capacity 44 00:01:43,780 --> 00:01:44,790 ‫to higher number, 45 00:01:44,790 --> 00:01:47,080 ‫but that's still less than a maximum capacity, 46 00:01:47,080 --> 00:01:48,850 ‫then you can scale out as needed. 47 00:01:48,850 --> 00:01:51,650 ‫That means scale out means adding EC2 instances 48 00:01:51,650 --> 00:01:53,570 ‫and so therefore your ASG can grow bigger 49 00:01:53,570 --> 00:01:54,560 ‫and bigger and bigger. 50 00:01:54,560 --> 00:01:58,870 ‫In this instance, the maximum capacity is seven. 51 00:01:58,870 --> 00:02:02,210 ‫As I said, the ASG also works with a load balancer. 52 00:02:02,210 --> 00:02:06,090 ‫So if we have four instances registered in our ASG, 53 00:02:06,090 --> 00:02:08,760 ‫then the ELB is going to distribute traffic 54 00:02:08,760 --> 00:02:11,070 ‫to all these instances right away 55 00:02:11,070 --> 00:02:14,530 ‫and so your users can access a load balanced website. 56 00:02:14,530 --> 00:02:17,480 ‫But the ELB also has the ability 57 00:02:17,480 --> 00:02:20,460 ‫to check for the health of your EC2 instances 58 00:02:20,460 --> 00:02:21,830 ‫using the health check 59 00:02:21,830 --> 00:02:24,880 ‫and that health check can be passed on to the ASG. 60 00:02:24,880 --> 00:02:27,880 ‫That means that the ASG can terminate EC2 instances 61 00:02:27,880 --> 00:02:31,370 ‫if they are deemed unhealthy by the load balancer, 62 00:02:31,370 --> 00:02:32,970 ‫which is very handy. 63 00:02:32,970 --> 00:02:36,390 ‫Also, if you scale out, that means if you add EC2 instances, 64 00:02:36,390 --> 00:02:39,300 ‫then of course the ELB is going to send traffic 65 00:02:39,300 --> 00:02:41,620 ‫to them as well and spread the load. 66 00:02:41,620 --> 00:02:43,470 ‫Therefore, it's a really great combination 67 00:02:43,470 --> 00:02:47,110 ‫to use a load balancer and an auto scaling group. 68 00:02:47,110 --> 00:02:49,120 ‫Now, in terms of attributes to create your ASG, 69 00:02:49,120 --> 00:02:51,330 ‫you need to create a launch template. 70 00:02:51,330 --> 00:02:53,050 ‫There used to be a thing called launch configurations 71 00:02:53,050 --> 00:02:55,460 ‫but it's deprecated, but the idea is the same. 72 00:02:55,460 --> 00:02:57,230 ‫A launch template contains information 73 00:02:57,230 --> 00:03:01,230 ‫on how to launch EC2 instances within your ASG. 74 00:03:01,230 --> 00:03:03,240 ‫So you have information about the AMI 75 00:03:03,240 --> 00:03:06,260 ‫and the instance type, the EC2 user data, 76 00:03:06,260 --> 00:03:10,090 ‫the EBS volumes, security groups, SSH key pair, 77 00:03:10,090 --> 00:03:12,580 ‫IAM roles for your EC2 instances, 78 00:03:12,580 --> 00:03:14,550 ‫network and subnet information 79 00:03:14,550 --> 00:03:18,120 ‫as well as load balancer information and more if you want. 80 00:03:18,120 --> 00:03:20,450 ‫And so all these parameters look a lot like 81 00:03:20,450 --> 00:03:25,110 ‫the ones we specified when we created an EC2 instance. 82 00:03:25,110 --> 00:03:27,850 ‫On top of it, your ASG has a min size, 83 00:03:27,850 --> 00:03:30,640 ‫a max size and an initial capacity we need to define 84 00:03:30,640 --> 00:03:33,130 ‫as well as scaling policies. 85 00:03:33,130 --> 00:03:34,860 ‫Talking about scaling policies, 86 00:03:34,860 --> 00:03:37,440 ‫let's see how CloudWatch alarm integrates with auto scaling. 87 00:03:37,440 --> 00:03:40,100 ‫So you don't know what CloudWatch is yet of course, 88 00:03:40,100 --> 00:03:42,700 ‫but let me just tell you a little bit about it right now. 89 00:03:42,700 --> 00:03:45,090 ‫So it's possible to scale in and out, 90 00:03:45,090 --> 00:03:47,610 ‫an ASG based on CloudWatch alarms. 91 00:03:47,610 --> 00:03:49,260 ‫So for example, we have an ASG right here 92 00:03:49,260 --> 00:03:51,050 ‫with three EC2 instances 93 00:03:51,050 --> 00:03:53,300 ‫and the alarm is going to be triggered 94 00:03:53,300 --> 00:03:56,770 ‫and therefore we're going to get a scale out activity. 95 00:03:56,770 --> 00:03:58,620 ‫So what would trigger an alarm? 96 00:03:58,620 --> 00:04:01,460 ‫Well, it's a metric you can return, for example, 97 00:04:01,460 --> 00:04:05,270 ‫for the average CPU or any custom metric you want. 98 00:04:05,270 --> 00:04:07,840 ‫So for example, if the average CPU 99 00:04:07,840 --> 00:04:10,720 ‫as a whole for your ASG is too high, 100 00:04:10,720 --> 00:04:12,840 ‫then you need to add EC2 instances 101 00:04:12,840 --> 00:04:15,300 ‫and therefore the alarm is going to be triggered 102 00:04:15,300 --> 00:04:18,200 ‫and is going to trigger a scaling activity 103 00:04:18,200 --> 00:04:19,430 ‫in your auto scaling group 104 00:04:19,430 --> 00:04:21,410 ‫and this is why it's called an auto scaling group 105 00:04:21,410 --> 00:04:23,200 ‫because paired with alarms, 106 00:04:23,200 --> 00:04:27,110 ‫there is an automatic aspect of scaling behind the scenes. 107 00:04:27,110 --> 00:04:29,700 ‫So based on the alarm, we can create scale out policies. 108 00:04:29,700 --> 00:04:31,920 ‫That means increasing the number of instances 109 00:04:31,920 --> 00:04:33,830 ‫or we can create scale in policies 110 00:04:33,830 --> 00:04:35,940 ‫to decrease the number of instances. 111 00:04:35,940 --> 00:04:39,080 ‫And all these things together are what composes ASG. 112 00:04:39,080 --> 00:04:42,030 ‫I hope you liked it and I will see you in the next lecture.