EC2 Auto Scaling life cycle hooks allow you to receive notice of a pending life cycle event and perform some action before the event takes place. Currently, you can be notified of the following life cycle hook events:
- EC2_INSTANCE_LAUNCHING: Raised when an EC2 instance is about to be launched
- EC2_INSTANCE_TERMINATING: Raised when an EC2 instance is about to be terminated
In general, you don't need to worry about EC2_INSTANCE_LAUNCHING events, however anybody who runs a production-grade ECS cluster should be interested in EC2_INSTANCE_TERMINATING events, given an instance that is about to be terminated may be running containers with active end user connections. Once you have subscribed to a life cycle hook event, the EC2 Auto Scaling service will wait for you to signal that the life cycle action can proceed. This provides you with a mechanism that allows you to perform graceful tear down actions in the case of an EC2_INSTANCE_TERMINATING event, and this is where you can leverage ECS container instance draining.