I'm planning to run an ECS cluster with an ALB in front of spot instances.
As an example: A user's request enters a container that is running on spot, but before getting the response, the spot instance is terminated. That will return an error, right?
How can I resolve this type of issue?
Is there any way to stop sending requests before it was gone?
You can enable something called as ECS_ENABLE_SPOT_INSTANCE_DRAINING
, it will change the instance to draining state and no new requests would come to this instance. The time frame is 2 minutes, if your requests will be longer then the user would get error.
AWS Blog: Best practices for handling EC2 Spot Instance interruptions - Check the "Inside a Container Running on Amazon ECS" section