Task 1:Create a Launch Configuration
1.In the AWS Management console,under Services,Click EC2 under Compute.
2.In the left navigation pane,Click Launch Configurations under Auto Scaling.
A Launch Configuration is a template that an Auto Scaling group uses to launch EC2 instances.
3.Click on Create launch configuration->Select the AMI ( Amazon Linux 2 AMI (HVM), SSD Volume Type – ami-06bcd1131b2f55803 ) ->Select t2.micro General Purpose Instance Type->Click Next:Configure details and enter the values – Name, & IP Address Type(Select Assign a public IP to every instance) ->Click Next Add Storage.
4.Leave the Values a Default for Storage.(You can change as per your needs)->Click Next Configure Security Group->Select an existing security group(Select this if you have already created,if not create a new one refer to my posts on how to create security group under AWS Networking & Content Delivery Category)->Click Review->Click Create launch configuration.(Select the Key Pair if not create new one).
Your launch configuration has been created and you will be prompted to create an Auto Scaling group.
Task 2:Create an Auto Scaling group
The Launch Configuration defines what should be launched,while the Auto Scaling group defines how many instances to launch and where to launch them within your network.
1.Click on Create an Auto Scaling group and then enter the values for Group Size(Here we are entering only 1 we can change as per our requirements),Select VPC for Network,Select the Subnets. We are not entering any values for Advanced Details as this is just a demo to showcase on how to use Auto Scaling ->Click Next:Configure scaling policies.
2.We are going to keep default option ,Auto Scaling will keep this group at its initial size.This means that it will keep one instance always operating.If the instance fails,it will be automatically replaced->Click Review.
If we want to Select other option ,Use scaling policies to adjust the capacity of this group.
Here it will give you the option of scaling the instances between minimum and maximum instance sizes of your group.You can define Name,Select Metric type (here just for understanding I am selecting Average CPU Utlization),Target Value defines the CPU Utilization Percentage and other details.Based on these details given in the scaling policy,Auto Scaling will always ensure your instances are sized based on the minimum and maximum size of your group.
Based on the requirements ,if notification is needed we can configure Notifications and Tags for this Auto Scaling group.(we are not using this for our demo).But we have the option to get notified during instance launches,terminate or any failures and mention the mail id’s of the recipients to get notified.
3.Click Review->Click Create Auto Scaling group.
Task 3:Verify Your Auto Scaling group
Now that we have created your Auto Scaling group,we can verify that the group has launched your EC2 instances.
If you go to EC2,you will see the new EC2 instance up and running.
To verify ,we can Click on Auto Scaling groups under Auto Scaling to see the new EC2 instance getting launched.
Click the Activity History tab.
Click the Instances tab.
The Lifecycle column contains the state as InService of your newly launched instance.The Health Status column shows the result of the EC2 instance health check on your instance.
Task 4:Test Auto Scaling
Since during the configuration of Auto Scaling group, we selected the Group size as 1 instance and selected Auto Scaling will keep this group at its initial size .Therefore ,if you terminate the running instance,Auto Scaling must launch a new instance to replace it.
1.Lets go to EC2 console->Select the Instance which got created using Auto Scaling group.Here the instance ID is i-003083c1383d57775 .On the Actions menu->Select Instance state->Select Terminate->Select Yes Terminate. The instance will change to shutting down and then will be terminated after few seconds.
2.Now after few seconds the instance would be terminated.In the left navigation pane,Click Auto Scaling groups->Click Instances tab.
Here once the old instance is terminated ,you will see a new instance appear as pending or InService. The default cooldown for the Auto Scaling group is 300 seconds ,so it may take about 5 minutes until you see the new instance scaled up.
As you see ,the new instance has been scaled up with new instance id i-094143c73bc28f5dd and in healthy state.
3.Return to the Activity History tab. All the Scaling activities are logged here.
This is how Auto Scaling feature can be used to Scale Up or Scale Down EC2 instances based on the Auto Scaling group and Scaling Policies defined.