amazon-web-servicesamazon-ec2spot-instances

How to terminate an EC2 instance from spot fleet?


I have a use case in which I am creating a Spot Fleet via AWS Management Console by referencing spot-fleet-requests-doc.

Spot fleet launches Spot Instances and On-Demand Instances as per the target capacity defined in the Spot Fleet request. I was wondering if there is a way I can terminate an spot instance/on demand instance from the spot fleet if needed ?

Any leads/pointers will be appreciated. Thank you!


Solution

  • Yes, you can terminate any instance in the fleet. if you're using AWS Console, go to EC2-> Instances -> Select the instances you want to terminate and use the Instance state button to terminate the selected instances.

    Two things to note here:

    1. If you selected Maintain target capacity while creating the Spot fleet, the fleet will replace the terminated instances and start new ones to maintain the desired capacity.
    2. To stop the fleet from starting new instances, at AWS Console, got to EC2-> Spot Requests -> Select the fleet -> Click Actions button and choose Modify target capacity. Set the new desired capacity, uncheck the Terminate instances checkbox if you want to pick and terminate the instances yourself.