1
votes

I'm running custom transactional tasks on my EC2 instances. The decision to shutdown or not an instance is taken under many conditions by special process running on this instance. The termination should be done by instance itself, because Autoscaling Group does not know when data processing is finish. Do the following steps are consistent with the philosophy of AWS?

  1. Creates AMI with option: "Shutdown behaviour: Terminate".
  2. Autoscaling group creates a new instance with option "Protect From Scale In".
  3. Custom process on EC2 calls command:

    $ sudo shutdown -P now
    

    to terminate an instance in proper time.

Is that correct? Or maybe AWS has some tools to do that, eg. emit special signal to terminate an instance?

Thank you

1
Why the "Protect From Scale In"? That will prevent the instance from terminating, which is what you want it to do no?Rodrigo M
That will prevent the instance from terminating by Autoscaling Group. The termination should be done by instance itself, because Autoscaling Group does not know when data processing is finish on EC2.User
Why use an autoscaling group at all?Frederick Cheung
For scaling "up". Instances are workers for ZeroMQ.User
What is your rule for determining when to scale-in? Does an instance always kill itself as soon as it has done some processing, or is there a CloudWatch alarm that should be used to trigger scaling-in?John Rotenstein

1 Answers

0
votes

That process has one issue I believe:

In step 1, the "Shutdown behaviour: Terminate" option is not an AMI level setting. It is a launch time setting, for instances launched outside of an autoscaling group.

Within an Autoscaling Group, there is no option to configure a Launch Configuration with the equivalent of "Shutdown behaviour: Terminate". Presumably, ASG instances must be terminated during scale in events.

The simple approach would be to have the instance call the AWS CLI terminate-instances command:

aws ec2 terminate-instances --instance-ids i-xxxxxxxx

You would need to acquire the instance id from the AWS Metadata in order to run the terminate-instances command.