{"id":15275,"date":"2014-08-31T20:19:59","date_gmt":"2014-08-31T14:49:59","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=15275"},"modified":"2016-06-24T11:06:30","modified_gmt":"2016-06-24T05:36:30","slug":"aws-auto-scaling-lifecycle-hooks","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/aws-auto-scaling-lifecycle-hooks\/","title":{"rendered":"AWS Auto Scaling -Lifecycle Hooks"},"content":{"rendered":"<p>Typically there could be some scenario , when a scale in event occurs and Auto Scaling determines that an instance is no longer necessary, it immediately puts the instance into Terminating\u00a0\u00a0state. The instance remains in this state until the instance fully terminates.\u00a0By default, \u00a0We cannot connect to an instance that is terminating<\/p>\n<p>Recently aws has given the addition features that give you additional control over the EC2 instances managed by each of your <a href=\"http:\/\/www.tothenew.com\/blog\/aws-autoscaling-group-configured-with-elb-and-alarms-in-boto-python\/\">Auto Scaling Groups<\/a> which is called <strong>Auto Scaling -Lifecycle Management<\/strong>\u00a0.<\/p>\n<p>Now we can choose to put the instance in a\u00a0<strong>Terminating:Wait<\/strong>\u00a0state using Auto Scaling&#8217;s\u00a0<span class=\"command\"><strong>PutLifecycleHook<\/strong><\/span>\u00a0command. This option allows you to access the terminating instance.<\/p>\n<h3>Create a life-cycle hook to retrieve logs from a terminating server<\/h3>\n<p>1. Create a notification target to\u00a0receives the SNS notification that an instance is in the Pending:Waiting\u00a0\u00a0state and\u00a0\u00a0make a note of its Amazon Resource Name (ARN).<\/p>\n<p>2. Create an IAM role to \u00a0AutoScaling Notification Access and\u00a0make a note of its Amazon Resource Name (ARN).<\/p>\n<p>3. Use below mentioned command to create life-cycle hook<\/p>\n<p>[js]&quot;aws autoscaling put-lifecycle-hook &#8211;auto-scaling-group-name QA-Server-AS-Group &#8211;lifecycle-hook-name TestHook &#8211;lifecycle-transition autoscaling:EC2_INSTANCE_TERMINATING &#8211;role-arn arn:aws:iam::651968884577:role\/Autoscaling-life-cycle &#8211;notification-target-arn arn:aws:sns:ap-southeast-1:651968884577:QA-Server-Memory&quot;[\/js]<\/p>\n<p><span style=\"color: #000000;\">Note : Now you have created a lifecycle hook that applies to any instances that are being terminated from the Auto Scaling group\u00a0When a scale in event occurs, the Auto Scaling group puts the instance in a <strong>Terminating<span style=\"color: #000000;\">:Wait<\/span><\/strong>\u00a0state.Now\u00a0connect to the instance to download the log files you required.\u00a0<\/span><\/p>\n<p><span style=\"color: #000000;\">By default, the instance remains in the <strong>Terminating:Wait<\/strong>\u00a0<\/span><span style=\"color: #000000;\">\u00a0state for 60 mintues.<\/span><span style=\"color: #000000;\">Auto Scaling continues the termination process,\u00a0If you take no action during that time.<\/span><\/p>\n<p>4. Use given command to check life-cycle-hooks once it is created.<\/p>\n<p>[js]&quot;aws autoscaling describe-lifecycle-hooks &#8211;auto-scaling-group-name QA-Server-AS-Group&quot;[\/js]<\/p>\n<p><span style=\"color: #000000;\">5. Use given command to delete \u00a0life-cycle-hooks once the debugging is done.<\/span><\/p>\n<p>[js]&quot;aws autoscaling delete-lifecycle-hook &#8211;auto-scaling-group-name QA-Server-AS-Group &#8211;lifecycle-hook-name TestHook&quot;[\/js]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Typically there could be some scenario , when a scale in event occurs and Auto Scaling determines that an instance is no longer necessary, it immediately puts the instance into Terminating\u00a0\u00a0state. The instance remains in this state until the instance fully terminates.\u00a0By default, \u00a0We cannot connect to an instance that is terminating Recently aws has [&hellip;]<\/p>\n","protected":false},"author":120,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[1174],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15275"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/120"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=15275"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15275\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=15275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=15275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=15275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}