AWS Autoscaling Groups

So we have now created our first instance of EC2. Now we will explore it.

On the Instances page, right click on Instance ID-->Connect. Select Session Manager. A new browser tab will open. Go to that new tab.

Another way to access our instance is via SSM. Click on Services on top left corner and type SSM in search bar. Click Session Manager.

Next page, click Session Manager on left bar menu. Select our newly created instance and click Start session. That's it. We are in our Instance. Congratulations.

We will terminate this session. In Services, click EC2. Click Instances. Next page, click Actions-->Instance state-->Stop.

Create an Image of our EC2 instance

On EC2 page, Click Instances from left menu. Click Actions-->Image-->Create Image

In Pop up, Type an Image name, Image description, and Click Create Image.

We can view our created image on main EC2 dashboard-->Snapshots

Note: This image can be used to launch more instances of EC2 in future.

Auto Scaling Groups

Amazon EC2 Auto Scaling helps ensure to have the correct number of Amazon EC2 instances available to handle the load for our application. We can create collections of EC2 instances, called Auto Scaling groups. We can specify the minimum number of instances in each Auto Scaling group, and Amazon EC2 Auto Scaling ensures that our group never goes below this size. We can also specify the maximum number of instances in each Auto Scaling group, and Amazon EC2 Auto Scaling ensures that our group never goes above this size. If we specify the desired capacity, either when we create the group or at any time thereafter, Amazon EC2 Auto Scaling ensures that our group has those many instances. If we specify scaling policies, then Amazon EC2 Auto Scaling can launch or terminate instances as demand on our application increases or decreases.

On EC2 dashboard, click Auto Scaling Groups on left menu. Click Create Auto Scaling Group. Wizard will start on next page. Click Get Started.

Next page, Create Launch Configuration. Since we have our own instance saved as an image. We will be using that. So click My AMIs on left menu.

Next page, select our image. Next page, we will keep the default CPU type and click Next: Configure Details. Next page, input Name for launch configuration and select IAM role from drop down. Click Next: Add Storage.

Next page, keep the default storage type. Click Next: Configure Security Group.

Next page, We will keep the default option of selecting "Create a new security group". Click Review.

Next Page, Click Create Launch Configuration. On popup, select Proceed without a key pair and Proceed.

Next page, Create Auto Scaling Group. Input Group Name. Keep the default Group Size and Network. Select two subnets from the drop down. Click Next: Configure Scaling Policies.

Next page, select Use scaling policies to adjust the capacity of this group. Scale between 1 and 2 instances. In Scale Group Size, select Metric Type: Average CPU Utilization. Input Target Value: 70. Instances need 60 sec to warm after scaling. Click: Next Configure Notifications.

Next page, Click Next: Configure Tags.

Next page, Click Review.

Next page, Click Create Auto Scaling Group.

Next page, we can see our Auto Scaling Group created. Click Instances on below Auto Scaling group information window. We can see our new instances in InService and Health Status.

Now click Instances on left menu. Next page, we can see both our instances. One stopped and one in running state.

Checking that Auto Scaling is Working

On Instances page, select the instance that is running and terminate it. Since our other instance is stopped, the Auto Scaling Group will detect the running instance as Unhealthy and will automatically launch a new instance. To check that, go to Auto Scaling Group page from left menu and click Instances on right side window. We will see that the Unhealthy Instance is removed and after 60 seconds a new instance is launched automatically.

Deleting the Auto Scaling Group

On our Auto Scaling Group page, Click Actions-->Delete. Our Auto Scaling Group will be deleted.

Go to Instances page and we can see both new instances are now terminated. While the first instance that we created is stopped.

Now we will move on to Elastic Load Balancer