Control EC2 instances that gets removed by an AutoScalingGroup using Amazon Web Services

0 votes
I have foreseen a problem that could happen with my application but I am unsure if it is possible to solve, and perhaps the architecture needs to be redesigned.

I am using an AutoScalingGroup (ASG) on AWS to create EC2 instances that host game servers that players can join. At the moment, the ASG is scaled manually via a matchmaking API which changes the desired capacity based on its needs. The problem occurs when a game server is finished.

When a game finishes, it signals to the matchmaker that it is finished and needs terminating, and the matchmaker will then scale down the ASG accordingly, however, it doesn't seem to know exactly which instance to remove, and it won't necessarily be the one that needs terminating.

I can terminate the instance, but then as the ASG desired capacity is never changed when the instance is terminated, another server is created.

Is there a way I can scale down the ASG, as well as specifying which servers to remove from the group?
Sep 27, 2018 in AWS by bug_seeker
• 15,510 points
1,394 views

1 answer to this question.

0 votes

In a nutshell, the default termination policy during scale in is designed to remove instances that use the oldest launch configuration.

Currently, Amazon EC2 Auto Scaling supports the following termination policie:
OldestInstance Terminate the oldest instance in the group. This option is useful when you're upgrading the instances in the Auto Scaling group to a new EC2 instance type. You can gradually replace instances of the old type with instances of the new type.
NewestInstance Terminate the newest instance in the group. This policy is useful when you're testing a new launch configuration but don't want to keep it in production.
OldestLaunchConfiguration Terminate instances that have the oldest launch configuration. This policy is useful when you're updating a group and phasing out the instances from a previous configuration.
ClosestToNextInstanceHour Terminate instances that are closest to the next billing hour. This policy helps you maximize the use of your instances and manage your Amazon EC2 usage costs.
Default Terminate instances according to the default termination policy. This policy is useful when you have more than one scaling policy for the group.

Instance protection

One of the possible solutions could be to use Instance protection. The auto-scaling provides an instance protection to control whether instance can be terminated when scaling-in.

Therefore, enable the instance protection for ASG to protect instances from scaling-in by default. Once you are done with you server, decrease a value of desired number of instances, remove instance protection from particular instance (either using CLI or SDK; note that this protection remains enabled for the rest of instances) and auto-scaling will terminate that exact instance.

For more information about instance protection, see Instance Protection

answered Sep 27, 2018 by Priyaj
• 58,020 points

Related Questions In AWS

0 votes
1 answer

How to synchronize sessions using Amazon Web Services?

I think what you are looking for ...READ MORE

answered Aug 18, 2018 in AWS by Archana
• 4,170 points
595 views
0 votes
1 answer
0 votes
1 answer

How do I create an alarm for my load balancer using the Amazon EC2 console?

Follow these steps: Open the Amazon EC2 console On ...READ MORE

answered May 17, 2019 in AWS by Rhea
1,645 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Explain how the buffer is used in Amazon web services?

In order to make system more efficient ...READ MORE

answered Jul 31, 2018 in AWS by Priyaj
• 58,020 points
5,370 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP