Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions factory/aws/src/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,28 @@ async fn destroy_instance(
id: &str,
force_stop: bool,
) -> Result<()> {
/*
* Before terminating an instance, attempt to initiate a forced shutdown.
* There is regrettably no force flag for termination (!) and if we don't do
* this first, AWS will sometimes wait rather a long (and billable) time
* before actually terminating a guest. It is difficult, as the saying
* goes, to get a man to understand something, when his salary depends upon
* his not understanding it.
*/
if force_stop {
info!(log, "forcing stop of instance {id}...");
ec2.stop_instances().instance_ids(id).force(true).send().await?;
}

info!(log, "terminating instance {id}...");
ec2.terminate_instances().instance_ids(id).send().await?;
ec2.terminate_instances()
.instance_ids(id)
/*
* If requested, perform a forced shutdown of the VM before terminating
* it, otherwise AWS waits until the instance stops on its own (still
* billing you for it!). Note that both `force` and `skip_os_shutdown`
* must be enabled for the instance to reliably shut down immediately:
*
* - `force` ensure the instance gets terminated if there is a problem
* with the underlying compute host.
*
* - `skip_os_shutdown` avoids sending an ACPI shutdown signal to the VM
* and immediately stops it, instead of waiting for the instance to
* shut itself down.
*
* https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-stop-methods.html
*/
.set_force(Some(force_stop))
.set_skip_os_shutdown(Some(force_stop))
.send()
.await?;

Ok(())
}
Expand Down