Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are people handling connection loss through downscaling in amazon auto scaling group?

As I understand it, when Amazon auto scaling groups downscale, any connections open to the terminated instance are just lost - there is no graceful termination.

I'm wondering how others are handling this.

My thinking is that the initiator of the connection should handle the failure as it should be able to deal with the situation where an instance fails rather than being deliberately terminated.

Any thoughts?

Thanks,

Pete

like image 436
Peter Whitfield Avatar asked Dec 11 '12 22:12

Peter Whitfield


People also ask

Can Amazon EC2 Auto Scaling group ASG auto handle the failure and replacement of an Amazon EC2 instance in the scaling group?

If you're using an Elastic Load Balancing load balancer, Amazon EC2 Auto Scaling gracefully detaches the impaired instance from the load balancer before provisioning a new one and attaching it to the load balancer. This is all done automatically, so you don't need to respond manually when an instance needs replacing.

What is the purpose of an Amazon Auto Scaling group?

AWS Auto Scaling lets you build scaling plans that automate how groups of different resources respond to changes in demand. You can optimize availability, costs, or a balance of both. AWS Auto Scaling automatically creates all of the scaling policies and sets targets for you based on your preference.

How does Auto Scaling manage traffic flow for ELB?

To use Elastic Load Balancing with your Auto Scaling group, attach the load balancer to your Auto Scaling group. This registers the group with the load balancer, which acts as a single point of contact for all incoming web traffic to your Auto Scaling group.


2 Answers

If you are using a load balancer you can switch on the connection draining option on the Instances tab. It allows you to set a time to wait for connections to be closed before terminating the instance. Max is 3600 seconds. See https://aws.amazon.com/blogs/aws/elb-connection-draining-remove-instances-from-service-with-care/

like image 54
Mikhail Janowski Avatar answered Nov 04 '22 01:11

Mikhail Janowski


The way I did it is with a lifecycle hook. Which can interrupt the termination process for a set amount of time (default 1 hour).

It is designed to be resumed once your work is complete but the timeout worked for a hacky connection draining.

You have the option of adding a hook to your Auto Scaling group instances in this state into a Terminating:Wait state. This state allows you to access these instances before they are terminated.

source: http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/AutoScalingGroupLifecycle.html

con: setup via CLI, but not too bad.

How to do that: http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/adding-lifecycle-hooks.html

When creating IAM you will need this policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "autoscaling:PutLifecycleHook",
        "autoscaling:DeleteLifecycleHook",
        "autoscaling:RecordLifecycleActionHeartbeat",
        "autoscaling:CompleteLifecycleAction",
        "autoscaling:DescribeAutoscalingGroups",
        "autoscaling:DescribeLifecycleHooks",
        "autoscaling:PutInstanceInStandby",
        "autoscaling:PutInstanceInService",
        "iam:AddRoleToInstanceProfile",
        "iam:CreateInstanceProfile",
        "iam:CreateRole",
        "iam:PassRole",
        "iam:ListInstanceProfiles",
        "ec2:Describe*"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}

Good luck!

like image 30
CoderDan Avatar answered Nov 04 '22 01:11

CoderDan