January 26, 2015
Auto Scalability Using Amazon Web Services
Auto Scalability is the key feature of cloud computing. The ability of AWS cloud to manage the capacity of your environment automatically is a huge advantage for availability of the application. It has also reduced a lot of burden from operation teams.
In this blog, I’II be focusing on deploying a MVC web application from Visual Studio to AWS cloud utilizing the auto scalability features of AWS.
AWS provides a deployment service called Elastic Beanstalk; which can create a scalable environment on AWS in just 5 minutes. Let us go through this in detail.
1. Download AWS toolkit for visual studio from https://aws.amazon.com/visualstudio/. The tool kit enables developers to develop, debug and deploy AWS solutions right from their favorite IDE, i.e. Visual Studio. Similar toolkits are available for Eclipse.
2. Create a new user profile in AWS using Identity and Access Management. These user credentials will be used to access AWS resources for Visual Studio. Refer to https://docs.aws.amazon.com/AWSToolkitVS/latest/UserGuide/tkv_setup.html. The user should be based on the principle of least privilege.
3. Create a new MVC application and deploy the same on AWS cloud by following the below steps.
a. Right click on the solution and choose “Publish to AWS”
b. Create a new deployment profile
c. Provide the application environment specific information
d. Set up the launch configuration setting for your environment. Here I am choosing a 2012 R2 server with IIS 8.5 with a very small EC2 instance type t2 micro. These instances should be further launched in a VPC.
I am not using RDS service for this deployment but we can configure the database right from this screen. The roles and permissions under which these services will be launch can be modified after the environment gets created.
e. As I configured the environment to run in a VPC, I need to setup the VPC options. I am using the default VPC for this blog.
I have already created 2 subnets as shown below. I am setting up the ELB to run in one subnet and EC2 instance to launch in the other subnet.
f. Configure IIS and .NET framework setting.
g. Review and deploy.
h. Refresh the node under AWS Elastic Beanstalk from left tree and check out the logs. The status of the environment should be launching.
Beanstalk will create and set up each service that is required for setting up a scalable environment. You will be amazed to see how much of the work of setting up for the environment is taken over by Beanstalk. If you look closely in the logs, the services it created and configured are the following services:
i. Auto Scaling
iv. Cloud Watch
i. You can access logs that can be helpful to fix any setup issues. You can download the logs from S3 by clicking on logs.
j. Check the status of the environment and if it is “Environment is healthy” you are good to access the application by clicking on the URL
k. The environment can always be tweaked as per the requirement from the AWS console. Let me add 2 more alarms that will trigger the spawning of new server. The alarms will be based on CPU utilization. The first one will spawn up a new EC2 instance if CPU load remains higher than 60% for a minute. The other alarm will bring down an EC2 instance if CPU load remains lower than 10% for 1 minute.
l. Now let us increase the load on the application. The application that I have built has a button which can increase the load on CPU. After a couple of minutes the CPU utilization will increase over the threshold and Auto Scaling will spawn another EC2 instance in the environment.
m. The request to the server will now be shared between these 2 instances. ELB will redirect my request to these 2 different machines automatically. See below how the Server IP is different for the 2 different requests.
n. Don’t put any further load on the server and you will see after a few minutes that the Auto Scale service will bring down one EC2 instance.
o. So this is how auto scaling works. You must have noticed that the CPU usage indicator that has been shown on the above screens is 0. That is a bug in the code. So I need to fix and redeploy the application on the AWS environment. To do that, just republish to the Environment as below.
p. As before, check the status within the Elastic Beanstalk service. It should first be in “updating” state and then should change into “Environment is healthy” state.
q. The new code is deployed successfully on top of the existing environment. Follow the below steps to run the application and validate the setup again:
i. Access the web application
ii. Increase the load
iii. See the CPU utilization – if it goes above 60%, it should spawn one more EC2 instance
iv. Check the number of EC2 instances running. There should be 2 or more instances running now
v. Access the web application again. ELB should send the requests to the other server now as load on the other server is not high
vi. Wait for a couple of minutes more so that CPU can come below 10% for 1 minute
vii. Check the EC2 instance; there should be only one instance running again
I hope you have realized the power of Beanstalk and AWS auto scaling capability. I will appreciate your feedback in the comments section!