Launching our new stack

We will save those changes, generate our CloudFormation template and update our stack:

$ git add nodeserver-cf-template.py
$ git commit -m "Using autoscaling group instead of individual EC2 instances"
$ git push
$ python nodeserver-cf-template.py > nodeserver-cf.template

Then update (or recreate) the Hello World application with the following steps:

  1. Open https://console.aws.amazon.com/cloudformation in your browser.
  2. Select the helloworld-production stack and, in the Action menu, select Update stack (or go through the usual steps to create a CloudFormation stack).
  3. Select the new template file nodeserver-cf.template and click Next. The new parameters page looks a lot more complete than previously:
  1. We can opt for scaling our stack vertically by selecting a different instance type than t2.micro. Note that only t2.micro is part of the free tier. For the purpose of the book, we can stick with t2.micro.
  2. Keep or select your key pair.
  3. On the next field, select all the public subnets available. There should be one per availability zone. If AWS was to have some issue with a particular availability zone (AZ), you could decide to update your stack and exclude the subnet targeting this particular AZ.

 

  1. On the next option, we can select to start with anywhere between two and five instances. We will set this option set to our default, 3. Later, thanks to our auto-scaling rules, AWS will automatically downscale our cluster to two hosts, which is the minimum required in order to keep our service highly available.
  2. Finally, select the VPC ID there should only be one – and click Next.
  3. On the next screen, click Next again. This will bring us to the review screen:
  1. On that screen, we can confirm that the stack will do what we expect it to do, click on the checkbox to acknowledge the changes made to IAM resources, and click on Update.
This change is somewhat transformative and it highlights one of the reasons why using a cloud infrastructure is so powerful. Our production cluster is now able to scale dynamically with the traffic. As soon as we see a traffic spike, the auto-scaler will add instances and, once the spike of traffic is over, those extra instances will automatically be terminating, allowing us to add more resources only when needed. By relying on Auto Scaling groups and CloudWatch, we were able to implement it in just a handful of steps. Without those tools, recreating the same system could take weeks, if not longer.

We can track changes on how our cluster scales with the following command:

$ aws autoscaling describe-scaling-activities  

Since our application doesn't get any traffic, after a few minutes, this command will show the termination of one of our three EC2 instances as the CPUTooLow alarm will have been triggered.

In addition, our application has a new endpoint. We can extract it using the same command we used in Chapter 3, Treating Your Infrastructure As Code:

$ aws cloudformation describe-stacks 
--stack-name helloworld-production
--query 'Stacks[0].Outputs[0]'
{
"Description": "Application endpoint",
"OutputKey": "WebUrl",
"OutputValue": "http://helloWorl-LoadBala-1ABKQHK92ZOJO-1157159557.us-east-1.elb.amazonaws.com:3000"
}

But presently, nothing is running as we didn't deploy our application to the Auto Scaling group yet. For that, we will need to update CodeDeploy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset