I have created a custom AMI wherein a service xxx is started when aws instance gets started and service xxx gets stopped when that aws instance gets stopped. I have wrapped that ami under CloudFormation's AWS::AutoScaling::AutoScalingGroup. When a new instance gets added using auto scaling group the xxx service too gets started on it. But when I reduce the number of desired instances the xxx does not get stopped.
So reducing desired numInstances in autoscaling group simply terminates the instance without stopping it?
How do I get the notification to stop the xxx service before instance termination?