Please note that this course has been replaced with a new version that can be found here: https://cloudacademy.com/course/compute-saa-c03/compute-saa-c03-introduction/
This section of the Solution Architect Associate learning path introduces you to the core computing concepts and services relevant to the SAA-C02 exam. We start with an introduction to the AWS compute services, understand the options available and learn how to select and apply AWS compute services to meet specific requirements.
Want more? Try a lab playground or do a Lab Challenge!
- Learn the fundamentals of AWS compute services such as EC2, ECS, EKS, and AWS Batch
- Understanding how load balancing and autoscaling can be used to optimize your workloads
- Learn about the AWS serverless compute services and capabilities
Hello and welcome to this lecture where I'll focus on the different components of EC2 auto scaling, to help you understand how the process and service works. There are two distinct steps to the configuration. The first step is the creation of the launch configuration or launch template. And the second part is the creation of an auto scaling group.
When using EC2 auto scaling, you can either create a launch configuration or launch template. Both define how an auto scaling group builds new EC2 instances. They both answer a number of questions required when launching a new instance, such as which Amazon Machine Image to use or AMI, which instance type to select. If you'd like to use Spot Instances to help lower costs. If and when public IP addresses should be used for your instances. If any user data is required for automatic scripting on first boot. What storage volume configuration should be used, and what security group should be applied. You will probably be familiar with most of these steps if you have ever created an EC2 instance manually, it's much the same.
A launch template is essentially a newer and more advanced version of the launch configuration. Being a template you can build a standard configuration allowing you to simplify how you launch instances for your auto scaling groups. Let me now demonstrate how to create both a launch configuration and a launch template.
As you can see, I'm logged into my AWS account and I'm at the Management Console. And to create our launch templates and launch configurations we need to go into EC2 under compute. So let's take a look. Now I'm going to start by creating the launch template first. And then after that, I'll create the launch configuration so you can see the differences between them.
Now on the left hand side here, under instances, you can see launch templates. So if you select that, then it's just a quick splash screen here, just saying welcome to launch templates. And this gives you a brief summary of what it is. So to create a launch template we'll click on the blue create launch template button. Now here we have a single page with a number of configurable parameters on them. So let's go through each of them and take a look. So firstly, we can either create a new template or create a new template version. Now as I don't have an existing template, we can't create a new version of that template. So let's start from scratch by creating a new template. Let's give this a name. I'll just call this launch template. And a description of demo. Now here we can specify the source template, which essentially allows you to create a template from an existing template that you might already have. And as I explained, I don't have any other templates at the moment. So we can't do that and I just want to show you how to create a template from scratch anyway. Now further down we have launch template contents. Now this is where we started getting to the actual configuration of what we're going to launch.
And we can start by selecting the AMI ID. If we click on the search for AMI, we can have a look at the different catalogs. Either quick start if you have any of your own AMIs on the marketplace or the community AMIs. Let's just go with a quick start. And then we can select an AMI, let's just go with the top one here, the Amazon Linux. And select AMI, now we can select an instance type. Let's just go for a t1 micro. And if we have any existing key pairs, we can select an existing key pair to allow us to connect to our instances. For this one, I'll just select an existing key pair. And then network type that this instance will reside in, whether it's in a VPC environment, or the classic environment, we're going to go with the VPC. Now here we can also attach any security groups Again as a drop down list to allow you to select an existing security groups that you might have. So I'll just select a couple of different groups here. Now further down, if you want to add any additional network interfaces, then you can do so here simply by clicking on add network interface and filling out the relevant fields. Don't need to do that in this example. Now here we have storage volumes. So I'll come with an eight gig EBS volume, general purpose. And we can specify encryption here if we want to, and the delete on termination, either yes or no, and the IOPS et cetera. And we can add additional volumes if we want to as well here. Further down we can instance tags. So let's add a tag, say for example project cloud academy. And this will tag both the instance and the volume. If we go into advanced details. We can select if you want this to be a Spot Instance or not. We can select an instance profile which allows you to associate a role to your EC2 instance when it launches. We can select the shutdown behavior, whether you want it to terminate or simply stop when we shut it down. And there's a number of other more advanced options that you can select with regards to your instance. And then at the very bottom we have user data if you want to run any commands on boot. Now once you're happy with all of your information, all you need to do is simply click on create launch template. And that's it.
If we get on to close, we can now see our launch template has been created. And the default version is one and the latest version is one. We can create another launch template based on this and give it a different version if we want to. So let's see how the launch template compares to the launch configuration.
Now the launch configuration is further down on the left hand side on the auto scaling right at the bottom here. So if you click on launch configurations, and this is essentially the same as the launch template. Although the launch template has a few more options, and it's more simplistic in its creation and is the preferred method. However, you can still create launch configurations, so let's take a look. Click on create launch configuration. Now here we can select our AMI. And again, we have the different catalogs here like we do with the launch template. It's just presented differently essentially. Select the AMI. Here we can select our instance type. And again we had this option in the launch template. Here we can give it a name. Let's call this launch configuration. Again, you can select if you want to use Spot Instances, and you can select an IAM role. Whereas in the launch template you can select the instance profile. If we get on to advanced, there's not as many advanced options here as there is with the launch template as we had a much longer list. However, you do still have a number of options here should you need it such as user data, specifying the Kernel ID et cetera. If we go to storage. Again, it comes with the default storage for the instance type you selected. And again you can add new volumes if you need to. So again very similar to the launch template. Here you can select your security groups, so you can select an existing group. So again, you can just select the security groups that you need here. Then click on review. And here's a summary of all the options that you've selected. And once you're happy with those, simply click create launch configuration. And finally, here you can also choose a key pair or create a new key pair should you need to. So again, let's just let that cloud academy key pair. Then click create launch configuration. And there you go, there's our launch configuration.
So there's two different methods of creating that configuration to allow your auto scaling groups to know what instances to launch and how they should be configured. The main difference between the two is that the launch templates is presented all on a single page to allow you to quickly select your options rather than going through a number of different screens. And it also has a few more advanced features and options as well. Okay, that's the end of the demonstration, thank you.
Without either the launch configuration or launch template, auto scaling would not know what instance it was launching and to which configuration. So before you create your auto scaling group, you need to have your launch configuration defined. But what does the auto scaling group do? Well, the auto scaling group defines the desired capacity and other limitations of the group using scaling policies and where the group should scale your resources, such as which availability zone. Let's look at each of these details further via another demonstration on how to create an auto scaling group. And during this demonstration, I will create a new auto scaling group based on our previous launch template. And I'll set up an auto scaling policy defining when to both increase and decrease the group size. Let's take a look.
Again I'm within the AWS Management Console. And to create our auto scaling group, we need to go into EC2, which is under compute. And then if you scroll to the bottom on the left hand side, we can see under auto scaling, auto scaling groups, so let's click on that. And this is where we can create our group. Firstly we click on the blue button create auto scaling group. And here we can either create it from a launch configuration or a launch template. So let's select the launch template which is the new and preferred option. And down here we can select which launch template we would like to use. And this is the one that I created in the previous demonstrations. So once I've selected my launch template that I'd like to use, click on next step. Now we can give it a group name. So I just call this demo. If we had multiple versions of our launch template, then we can select the different versions there. But at the moment we just have the single version. With regards to the fleet, we can adhere to our launch template configuration. Or we can use a combination of different purchase options and instances. I just want to use the configuration that we used within our launch template. With regards to the group size, let's start with two instances in our auto scaling group. And I can select the appropriate VPC that I'd like this to be launched in. And once I select the VPC, then I can select the subnets that I'd like. So let's just select a couple of subnets in our VPC. Now if we go down to advanced details, here we have a number of other options. Now if you want to associate our auto scaling group to a load balancer, then we can do so here. And we can select our load balancer and target groups. But at the moment I'm going to leave this blank because in a later demonstration in the next lecture, I'm going to show you how to associate an existing auto scaling group with one of your new load balancers. So I'm just going to leave that blank for now. But if you did want to associate your auto scaling group to a load balancer during creation. then this is the place you do it. We have our instance protection down here. And we have an option protect from scale in. So if this is selected then during the scale in procedures, auto scaling won't terminate any instances that are protected. I'm just going to remove the options for now. And also and finally a service linked role is selected. And this enables access to AWS services and resources that are used or managed by auto scaling. Once we have our configuration set, we can move on to configuring scaling policies.
Now here, we have two options, we can keep this group at its initial size. And as you know I set it to two instances, or we can you scaling policies to adjust the capacity of the group. And that's what I'd like to do. Now I want to scale between two and five instances say. 'Cause that's the minimum and maximum number of instances that this group will scale to. Now I want to scale more auto scaling group using step or simple scanning policy. So I'm going to click on that. Now we have a policy here for increasing the group size and also a policy here for decreasing the group size. So the name for this policy, I'm just going to leave as increase group size. So auto scaling knows when to execute this policy, we need to set an alarm. So click on add new alarm. And this will send a notification. At that the moment I've got a notification set up as CADemo, which is an SNS topic. And I want this alarm to trigger whenever the average CPU utilization is greater than or equal to 75% for one consecutive period of five minutes. The name of this alarm will be deploy new instances. And then I simply click on create alarm. Now I want to take the action of adding just a single instance when the CPU utilization is greater than 75%.
Now we can do the same for the decrease group size, so whenever the average CPU utilization is less than or equal to 30%, for two consecutive periods of five minutes, and I'm going to call this remove instances and create that alarm. I'm going to say remove one instance when the CPU is less than 30%. Once your policies are set, you can click on configure notifications. So if you want to configure your notifications, simply click on add notification. And that's my SNS topic that I had. So whenever instances are launched, terminated, fail to launch and fail to terminate, I want to receive those notifications. Let's click on configure tags. And here, you can add any tags to auto scaling group. Just going to leave that blank for this demonstration, click on review. And here we have all of our configuration that we just made. Once you're happy with that, click on create auto scaling group.
And we now have our auto scaling group configured and except here the minimum and maximum instances two and five and the availability zones et cetera. Now at the bottom here you can go into the auto scaling group details. Here we can see it's launching two new instances because we said we want to start with two instances to start with. We can review our scaling policies. We can look at instances, monitoring, notifications, et cetera, et cetera. So if we go over to our instances, we should see two new instances that are launching. and here we can see that these two here are both initializing. So that's our two new instances that are running because of our auto scaling group which was based off of our launch template. And that's it.
In the next lecture, I should be looking at how both ELB and auto scaling combined can be used to manage your EC2 infrastructure.
Stuart has been working within the IT industry for two decades covering a huge range of topic areas and technologies, from data center and network infrastructure design, to cloud architecture and implementation.
To date, Stuart has created 150+ courses relating to Cloud reaching over 180,000 students, mostly within the AWS category and with a heavy focus on security and compliance.
Stuart is a member of the AWS Community Builders Program for his contributions towards AWS.
He is AWS certified and accredited in addition to being a published author covering topics across the AWS landscape.
In January 2016 Stuart was awarded ‘Expert of the Year Award 2015’ from Experts Exchange for his knowledge share within cloud services to the community.
Stuart enjoys writing about cloud technologies and you will find many of his articles within our blog pages.