Art Alone Enduring

Our creations outlive us: the vision and solace to the author and the artist, a caution to the architect. As I sorted through bags and boxes and old trunks carefully stacked in the basement of an old…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




CloudFormation Example for Auto Scaling Fargate Service

5 May 2021

by Thomas

Modern web applications need to scale well, both from a code and infrastructure perspective. While I believe that Lambda functions are a great platform to build off of for scalability, Fargate is also a valid option. With most developers being familiar with containers, Fargate gives us a great jumping-off point to run those containers in the cloud without getting in the way of how developers want to write applications. I’m bringing this up to mention that I understand the draw of developing with containers over developing for a Lambda function which is not as easy to run locally. Containers function the same in the cloud as they do on a local machine.

The template that I created is based on that original simple Fargate service template. The additions necessary were based around the auto scaling resources and a CloudWatch alarm to trigger the scaling. The auto scaling resources were an IAM role, an application auto scaling ScalableTarget, an application auto scaling ScalingPolicy to scale the service up, and another application auto scaling ScalingPolicy to scale the service down. The auto scaling target is meant to point the auto scaling policies at the right service and the scaling policies are meant to be triggered by an external event. The external event in my template's case is a CloudWatch alarm.

CloudWatch alarms can track metrics in AWS (built-in or user-defined) and trigger actions based on those metrics. For my template, I chose to scale up or down based on the number of requests received through the load balancer within one minute. If the amount of requests exceeds my predefined limit, the Fargate service is scaled up by adding a new task to help handle that load. After the amount of requests drops back below my predefined limit, the Fargate service is scaled back down. In this way, we can dynamically allocate the proper amount of computing resources behind a service.

I chose to use the number of requests per minute in my template, but the entire purpose was not to say that scaling based on requests is the best idea. I simply want to give a baseline or a starting point and I hope that someone can take that template and tweak it to best suit their needs. Basing a scaling policy on requests also made it much easier for me to test that everything was functioning properly. All I needed to do to verify that my service would scale is send a few requests to it and monitor the number of tasks that Fargate had spun up for my service. As I send more requests, I can monitor the alarm’s dashboard and watch the auto scaling events being dispatched as another form of verification.

Add a comment

Related posts:

The Mental Health Benefit of Pets

Most pet owners can agree that pets make us happy. It wasn’t until recently that scientists found evidence to back up those claims. There are obvious ways that pets help us, like giving us…

What is LaborX and what is its feature?

LaborX is a platform that helps people find jobs that suit their needs and skills. It was developed by Chrono.tech, a company focused on creating decentralized solutions for businesses. The platform…

These Legendary NFTs by Lei Melendres Are Up For Auction

Two legendary NFT cards by Lei Melendres will be auctioned for three weeks starting October 26 through November 15. These NFT cards are Lei’s favorites in the entire Inkvadyrz collection. Lei, who is…