Why did an EC2 instance that I terminated automatically re-launch?

Last updated: 2022-01-12

I terminated an Amazon Elastic Compute Cloud (Amazon EC2) instance. Then, another instance of the same type automatically launched on my account. Why did this happen, and how can I stop new instances from re-launching?

Short description

Some services allow you to automatically launch instances to replace terminated instances. This can improve the fault tolerance of an application.

For example:

  • You can configure your Amazon EC2 Auto Scaling groups to launch an instance that replaces an instance that's undergoing maintenance.
  • AWS Elastic Beanstalk environments usually include Auto Scaling groups by default.
  • You can configure the EC2 Fleet with the request type Maintain. In this scenario, EC2 Fleet places an asynchronous request for your desired capacity, and maintains capacity by automatically replenishing any interrupted Spot Instances.
  • You can configure the Spot Fleet request type as Maintain. In this scenario, Spot Fleet places an asynchronous request for your desired capacity, and maintains capacity by automatically replenishing any interrupted Spot Instances.

To prevent services from launching replacement instances, do the following:

Resolution

Note: The following actions permanently delete the selected AWS resources. Create a backup of your EC2 instance before proceeding with this resolution. The backup allows you to revert to your previous working state, if necessary.

Delete the Auto Scaling group

1.    Note the instance ID of the instance that re-launched.

2.    Confirm which Auto Scaling group is causing the re-launch:
Open the Amazon EC2 console. Amazon EC2 resources are Region-specific. Be sure that you're in the correct Region. If not, choose the correct Region from the navigation bar at the top of the screen.
Choose Auto Scaling groups in the left navigation pane and open it in a new window.
Choose the Auto Scaling group, and then select the Activity History tab.
Verify the instance ID of the re-launched instance.
Note: If the instance ID doesn't match or you don't have any Auto Scaling groups in this Region, skip to the following Terminate the Elastic Beanstalk Environment section.

3.    Choose Actions, Delete.

4.    Select Yes, delete.

5.    Select Instances from the left navigation pane. The instance is terminated and a new instance doesn't launch.

Terminate the Elastic Beanstalk environment

1.    Open the AWS Elastic Beanstalk console. Amazon EC2 resources are Region-specific. Be sure that you're in the correct Region, if not, choose the correct Region from the navigation bar at the top of the screen.

2.    Select Environments, and then choose the name of your environment from the list.

3.    Verify that the name of the re-launched EC2 instance is the same as the Elastic Beanstalk environment.

Note: If the instance ID doesn't match, skip to the following Delete the EC2 Fleet section.

4.    Choose Environment actions, and then choose Terminate environment.

5.    Confirm the environment termination. It might take a few minutes for Elastic Beanstalk to terminate the AWS resources running in the environment.

Delete the EC2 Fleet

EC2 Fleet is available only through the API or AWS CLI. Here we will use AWS CLI to delete the fleet.

1.    Make sure you have the AWS CLI installed and configured on your machine.

2.    Before proceeding, make sure you're in the correct Region, if not, set the correct Region by running following command:

aws configure

3.    Confirm if you have any existing EC2 Fleets by running following command:

aws ec2 describe-fleets

4.    To verify the EC2 instance ID to relaunch, run the following command to check information about specific EC2 Fleets. In the following command, replace fleet-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE with your EC2 fleet ID.

aws ec2 describe-fleet-instances --fleet-id fleet-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE

Note: If the instance ID doesn't match, skip to the following Cancel the Spot Fleet section.

5.    Run the following command to delete the EC2 Fleet and terminate currently running instances under the Fleet. In the following command,  replace fleet-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE with your EC2 Fleet ID.

aws ec2 delete-fleets --fleet-ids fleet-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE --terminate-instance

Cancel the Spot Fleet

1.    Open the Amazon EC2 console. Amazon EC2 resources are Region-specific. Be sure that you're in the correct Region, if not, choose the correct Region from the navigation bar at the top of the screen.

2.    Select Spot Requests.

3.    Confirm which Spot Fleet request is causing the re-launch. Select your Spot Fleet request. To see the configuration details, select Description.

4.    To verify the Spot Instances for the Spot Fleet, select Instances.

5.    Choose your Spot Fleet request.

6.    Select Actions, Cancel spot request.

7.    In Cancel spot request, verify that you want to cancel the Spot Fleet. Make sure Terminate instances is selected if you want to terminate the current instances and instances re-launched by this Spot Fleet. When you are ready, choose Confirm.

OR

You can use the following cancel-spot-fleet-requests command to cancel the specified Spot Fleet request and terminate the instances. In the following command, replace sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE with your Spot Fleet ID.

aws ec2 cancel-spot-fleet-requests --spot-fleet-request-ids sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE \--terminate-instances

Did this article help?


Do you need billing or technical support?