CodeDeploy can now call your application’s stop hook during ASG scale-ins so that you can complete ongoing tasks, release application resources, or close outgoing connections. Your application’s stop hooks can also be invoked during ASG instance refresh operations, allowing you to patch your instances without impacting your application’s availability.
Source:: Amazon AWS