Please note: This workshop version is now deprecated, and an updated version has been moved to AWS Workshop Studio. This workshop remains here for reference to those who have used this workshop before for reference only. Link to updated workshop is here: Launching EC2 Spot Instances.
Before closing this workshop, let’s make sure we clean up all the resources we created so we do not incur in unexpected costs.
When you are done with the FIS experiments, you can delete the experiment template.
aws fis delete-experiment-template --id $FIS_TEMPLATE_ID
To delete your Auto Scaling group using the CLI
aws autoscaling delete-auto-scaling-group --auto-scaling-group-name EC2SpotWorkshopASG --force-delete
When you are finished using your EC2 Fleet, you can delete the EC2 Fleet(s) and terminate all of the running instances.
To delete your EC2 Fleet and terminate the running instances using the CLI
aws ec2 delete-fleets --fleet-ids "${FLEET_ID}" --terminate-instances
You recall we created this instance with a specific Name tag. We will use the tag to search for the instance and then pass the instance-id
to the terminate-instances EC2 call.
export INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag-value,Values=EC2SpotWorkshopRunInstance" --query "Reservations[0].Instances[0].InstanceId" | sed s/\"//g)
aws ec2 terminate-instances --instance-ids $INSTANCE_ID
Let’s now cancel or delete the Spot Fleet request. You must specify whether the Spot Fleet should terminate its Spot Instances. If you terminate the instances, the Spot Fleet request enters the cancelled_terminating state. Otherwise, the Spot Fleet request enters the cancelled_running state and the instances continue to run until they are interrupted or you terminate them manually.
To cancel a Spot Fleet request and terminate the running instances using the CLI
aws ec2 cancel-spot-fleet-requests --spot-fleet-request-ids "${SPOT_FLEET_REQUEST_ID}" --terminate-instances
Finally, now that all the instances have been terminated, let’s delete the Launch Template.
aws ec2 delete-launch-template --launch-template-id "${LAUNCH_TEMPLATE_ID}"