SETUP Autoscaling
Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster. You can use Amazon EC2 to launch as many or as few virtual servers as you need, configure security and networking, and manage storage. Amazon EC2 enables you to scale up or down to handle changes in requirements or spikes in popularity, reducing your need to forecast traffic.
The following are stages to configure Auto Scaling Group:
A. Lunching EC2 Instance
B. Setup Launch configuration
C. Launch Auto Scaling Group
D. Terminate an instance in your Auto Scaling group
****************************************************************
A. Launching EC2 Instance
Step 1: Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
1. From the console dashboard, choose Launch Instance.
2. The Choose an Amazon Machine Image (AMI) page displays a list of basic configurations, called Amazon Machine Images (AMIs), that serve as templates for your instance. Select the AMI for Windows Server 2019 Base or later.
Notice that these AMIs are marked "Free tier eligible."
3. On the Choose an Instance Type page, you can select the hardware configuration of your instance. Select the t2.micro instance type, which is selected by default.
4. On the Choose an Instance Type page, choose Review and Launch to let the wizard complete the other configuration settings for you.
5. On the Review Instance Launch page, under Security Groups, you'll see that the wizard created and selected a security group for you. You can use this security group, or alternatively you can select the security group that you created when getting set up using the following steps:
a. Choose Edit security groups.
b. On the Configure Security Group page, ensure that Select an existing security group is selected.
c. Select your security group from the list of existing security groups, and then choose Review and Launch.d. On the Review Instance Launch page, choose Launch.
d. When prompted for a key pair, select Choose an existing key pair, then select the key pair that you created when getting set up.
Warning
Don't select Proceed without a key pair. If you launch your instance without a key pair, then you can't connect to it. When you are ready, select the acknowledgement check box, and then choose Launch Instances.
e. A confirmation page lets you know that your instance is launching. Choose View Instances to close the confirmation page and return to the console.
6. On the Instances screen, you can view the status of the launch. It takes a short time for an instance to launch. When you launch an instance, its initial state is pending. After the instance starts, its state changes to running and it receives a public DNS name. (If the Public IPv4 DNS column is hidden, choose the settings icon ( ) in the top-right corner, toggle on Public IPv4 DNS, and choose Confirm.
Left Scroll Bar
Right Scroll Bar
7. It can take a few minutes for the instance to be ready so that you can connect to it. Check that your instance has passed its status checks; you can view this information in the Status check column.
b. To create a launch configuration
1. Open the Launch configurations page of the Amazon EC2 console.
2. On the navigation bar, select an AWS Region. The Auto Scaling resources that you create are tied to the Region that you specify.
3. Choose Create launch configuration, and then enter my_launch_conf in the Name field.
4. For Amazon machine image (AMI), choose an AMI. To find a specific AMI, you can find a suitable AMI, make note of its ID, and enter the ID as search criteria.
To get the ID of the Amazon Linux 2 AMI:
a. Open the Amazon EC2 console.
b. In the navigation pane, under Instances, choose Instances, and then choose Launch instances.
c. On the Quick Start tab of the Choose an Amazon Machine Image page, note the ID of the AMI next to Amazon Windows AMI . Notice that this AMI is marked "Free tier eligible."
5. For Instance type, select a hardware configuration for your instance.
6. Under Additional configuration, for Advanced details, IP address type, make a selection. To provide internet connectivity to instances in a VPC, choose an option that assigns a public IP address. If an instance is launched into a default VPC, the default is to assign a public IP address. If you want to provide internet connectivity to your instance but aren't sure whether you have a default VPC, choose Assign a public IP address to every instance.
7. For Security groups, choose an existing security group. If you leave the Create a new security group option selected, a default SSH rule is configured for Amazon EC2 instances running Linux. A default RDP rule is configured for Amazon EC2 instances running Windows.
8. For Key pair (login), choose an option under Key pair options as instructed. Connecting to an instance is not included as part of this tutorial. Therefore, you can select Proceed without a key pair unless you intend to connect to your instance.
9. Choose Create launch configuration.
Now use Amazon EC2 Auto Scaling to create an Auto Scaling group and add the launch template or launch configuration to the group. Also include information such as the VPC subnets for the instances.
Use the following procedure to continue where you left off after creating either a launch template or a launch configuration.
C. To create an Auto Scaling group
1. On the Choose launch template or configuration page, for Auto Scaling group name, enter my-asg.
2. Choose Next.
The Configure settings page appears, allowing you to configure network settings and giving you options for launching On-Demand and Spot Instances across multiple instance types (if you chose a launch template).
3. [Launch template only] Keep Purchase options and instance types set to Adhere to the launch template.
4. Keep Network set to the default VPC for your chosen AWS Region, or select your own VPC. The default VPC is automatically configured to provide internet connectivity to your instance. This VPC includes a public subnet in each Availability Zone in the Region.
5. For Subnet, choose a subnet from each Availability Zone that you want to include. Use subnets in multiple Availability Zones for high availability.
6. Keep the rest of the defaults for this tutorial and choose Skip to review.
Note
The initial size of the group is determined by its desired capacity. The default value is 1 instance.
7. On the Review page, review the information for the group, and then choose Create Auto Scaling group.
Step 3: Verify your Auto Scaling group
Now that you have created an Auto Scaling group, you are ready to verify that the group has launched an EC2 instance.
To verify that your Auto Scaling group has launched an EC2 instance
1. Open the Auto Scaling groups page in the Amazon EC2 console.
2. Select the check box next to the Auto Scaling group that you just created.
A split pane opens up in the bottom part of the Auto Scaling groups page, showing information about the group. The first tab available is the Details tab, showing information about the Auto Scaling group.
3. Choose the second tab, Activity. Under Activity history, you can view the progress of activities that are associated with the Auto Scaling group. The Status column shows the current status of your instance. While your instance is launching, the status column shows PreInService. The status changes to Successful after the instance is launched. You can also use the refresh button to see the current status of your instance.
4. On the Instance management tab, under Instances, you can view the status of the instance.
5. Verify that your instance launched successfully. It takes a short time for an instance to launch.
The Lifecycle column shows the state of your instance. Initially, your instance is in the Pending state. After an instance is ready to receive traffic, its state is InService.
The Health status column shows the result of the EC2 instance health check on your instance.
D. Terminate an instance in your Auto Scaling group
Use these steps to learn more about how Amazon EC2 Auto Scaling works, specifically, how it launches new instances when necessary. The minimum size for the Auto Scaling group that you created in this tutorial is one instance. Therefore, if you terminate that running instance, Amazon EC2 Auto Scaling must launch a new instance to replace it.
1. Open the Auto Scaling groups page in the Amazon EC2 console.
2. Select the check box next to your Auto Scaling group.
3. On the Instance management tab, under Instances, select the ID of the instance.
This takes you to the Instances page in the Amazon EC2 console, where you can terminate the instance.
4. Choose Actions, Instance State, Terminate. When prompted for confirmation, choose Yes, Terminate.
5. On the navigation pane, under AUTO SCALING, choose Auto Scaling Groups. Select your Auto Scaling group and choose the Activity tab.
The default cooldown for the Auto Scaling group is 300 seconds (5 minutes), so it takes about 5 minutes until you see the scaling activity. In the activity history, when the scaling activity starts, you see an entry for the termination of the first instance and an entry for the launch of a new instance.
6. On the Instance management tab, the Instances section shows the new instance only.
7. On the navigation pane, under INSTANCES, choose Instances. This page shows both the terminated instance and the new running instance.
Clean up
You can either delete your scaling infrastructure or delete just your Auto Scaling group and keep your launch template or launch configuration to use later.
If you launched an instance that is not within the AWS Free Tier, you should terminate your instance to prevent additional charges. When you terminate the instance, the data associated with it will also be deleted.
To delete your Auto Scaling group
1. Open the Auto Scaling groups page in the Amazon EC2 console.
2. Select your Auto Scaling group (my-asg).
3. Choose Delete. When prompted for confirmation, choose Delete.
A loading icon in the Name column indicates that the Auto Scaling group is being deleted. When the deletion has occurred, the Desired, Min, and Max columns show 0 instances for the Auto Scaling group. It takes a few minutes to terminate the instance and delete the group. Refresh the list to see the current state.
Skip the following procedure if you would like to keep your launch template.
To delete your launch template
1. Open the Amazon EC2 console.
2. On the navigation pane, under INSTANCES, choose Launch Templates.
3. Select your launch template (my-template-for-auto-scaling).
4. Choose Actions, Delete template. When prompted for confirmation, choose Delete launch template.
Skip the following procedure if you would like to keep your launch configuration.
To delete your launch configuration
1. Open the Launch configurations page of the Amazon EC2 console.
2. Select your launch configuration (my-first-launch-configuration).
3. Choose Actions, Delete launch configuration. When prompted for confirmation, choose Yes, Delete.