I want EC2 instances to auto-terminate after 24h.
I do this with a script that is executed at instance launch:
shutdown | at now + 24 hours
The instance shuts down and the EBS volumes are terminated when the instance is terminated, so that's fine.
In the console the instance is indicated as not-reachable for some time, until it is declared as terminated. I wonder if it is bad practice to shut down an instance this way, and if terminating it with AWS CLI would be better.
The docs say:
When an EC2 instance is terminated using the terminate-instances command, the following is registered at the OS level:
The API request will send a button press event to the guest.
Various system services will be stopped as a result of the button press event. systemd handles a graceful shutdown of the system. Graceful shutdown is triggered by the ACPI shutdown button press event from the hypervisor.
- ACPI shutdown will be initiated.
- The instance will shut down when the graceful shutdown process exits. There is no configurable OS shutdown time.
The instance is in an auto-scaling group that runs a REST web service, so there are most likely requests just being executed.
- What happens to requests that are still being executed? (The REST service has a 30 seconds timeout, so requests are not running longer than that.)
- Is a termination with
shutdownless orderly than with the AWS CLI or a termination by the auto-scaling group?