Jibri on AWS - how to prevent instance termination during recording?

I have set up auto-scaling group to increase/decrease the Jibri instances based on demand for parallel recordings. I do scale-up by checking available count from “stats” endpoint on Jitsi server and pushing a metric to Cloudwatch. That works fine. However, I am not sure how to scale down the instances safely so that the ones that are currently recording are noted as “Busy” and not touched by auto-scaling group to terminate.
I did a test with 8 recorders and 4 of them doing recording at the same time. The auto-scaling group had to reduce 2 instances from the group. It had other free instances to pick but it killed one of the instances doing recording and a free instance. How do I prevent such a scenario ? Appreciate your help.

  1. enable scale-in protection for the scaling group, so that all the instances in that group are protected from scaling in by default

  2. inside each Jibri, as part of its scripts add a check whether it’s busy or recording and if for example it has been busy for N minutes, make a call to AWS to remove the scale-in protection

example:
aws autoscaling set-instance-protection --region=$region --instance-ids $instanceid --auto-scaling-group-name $ascgroupname --no-protected-from-scale-in

  1. once there is an instance in the group with removed protection, the scaling rules will do their job and will terminate that exact instance, not touching the other ones with protection

Thank you, will try that

One more tip - just in case, in the same script that removes the protection, you may want first to force re-enable the protection, just in case, at the beginning - the syntax is similar (“–protected-from-scale-in” instead of “–no-protected-from-scale-in”).

This way you’ll prevent any accidental unwanted removal of the protection and you’ll be sure that the protection is removed (and the instance is auto-terminated) only when you explicitly remove it in the script.

P.S.: All the other parameters to the command (region, instanceID, ASCGroupName) you can get from inside the instance by making calls to AWS.

Sure, noted, thanks

For some setups I use only the scale-out feature of AWS and disable the scale-in completely. I terminate the instances using the sudo poweroff command in the finalize script after each recording.

Will try that if the 1st option does not work fine