{"id":965,"date":"2019-10-04T16:36:33","date_gmt":"2019-10-04T14:36:33","guid":{"rendered":"https:\/\/blog.besharp.it\/?p=965"},"modified":"2021-03-24T17:53:31","modified_gmt":"2021-03-24T16:53:31","slug":"autoscaling-like-a-pro-how-to-use-ec2-auto-scaling-lifecycle-hooks-the-right-way","status":"publish","type":"post","link":"https:\/\/blog.besharp.it\/autoscaling-like-a-pro-how-to-use-ec2-auto-scaling-lifecycle-hooks-the-right-way\/","title":{"rendered":"Autoscaling like a pro: how to use EC2 Auto Scaling Lifecycle Hooks, the right way."},"content":{"rendered":"

Have you ever found it useful to access an EC2 instance, belonging to an Auto Scaling Group,<\/strong> to configure it or to simply get an idea of what went wrong before an unexpected termination?<\/span><\/p>\n

Well, in those cases EC2 Auto Scaling Lifecycle Hooks come in handy. In this article, we will give you a deep understanding of how Lifecycle Hooks work and what are their common use cases.<\/strong><\/span><\/p>\n

Just for clarity let\u2019s review EC2 Auto Scaling’s main characteristics and features, before going in detail with EC2 Auto Scaling Lifecycle Hooks. EC2 Auto Scaling<\/strong> is an AWS service that allows you to adapt the number of EC2 instances, serving your application, to meet the incoming load.<\/strong> These instances are logically grouped into Auto Scaling groups<\/strong> for which you can set the minimum, maximum and desired capacity.<\/strong> If there are no scaling policies attached to the Auto Scaling group, by default it maintains the desired amount of healthy instances, performing periodic health checks. Unhealthy instances will be terminated and replaced with new ones.<\/span><\/p>\n

Besides manual scaling, in which you actively change minimum, maximum or desired capacity, there are two automatic scaling<\/strong> types: Scheduled Scaling and Dynamic Scaling.<\/strong><\/span><\/p>\n

Scheduled Scaling<\/strong> should be used if you know in advance how your application\u2019s traffic patterns<\/strong> behave. In this case, you have to create a rule, called scheduled action, that instructs Auto Scaling to increase and decrease the Auto Scaling group\u2019s capacity based on predicted load changes.<\/strong><\/span><\/p>\n

Instead, when you need to scale in response to load changes that are not predictable<\/strong> Dynamic Scaling comes to the rescue.<\/strong> It provides different policy types that you can use to instruct Auto Scaling how to react to demand changes. There are three types of Dynamic Scaling policies:<\/span><\/p>\n