The initial problem was that if (max > instanceGroup.scalingOptions.maxDesired) was failing because max was only assigned to 0. That condition should have been if (req.body.maxDesired > instanceGroup.scalingOptions.maxDesired).
Moreover, I updated the validation logic to make sure the new max we are validating against has the same value as the max used in launchProtectedInstanceGroup. Therefore the current validation will not care if the new maxDesired is lower or higher than the old max, will only care if the new maxDesired is correct, meaning new launched instances + current desired <= new maxDesired.
…as in launch protected
The initial problem was that if (max > instanceGroup.scalingOptions.maxDesired) was failing because max was only assigned to 0. That condition should have been if (req.body.maxDesired > instanceGroup.scalingOptions.maxDesired).
Moreover, I updated the validation logic to make sure the new max we are validating against has the same value as the max used in launchProtectedInstanceGroup. Therefore the current validation will not care if the new maxDesired is lower or higher than the old max, will only care if the new maxDesired is correct, meaning new launched instances + current desired <= new maxDesired.