EC2 Shutdown Behavior
Key Points
- Default Shutdown Behavior: By default, when a shutdown command is issued from within the operating system of an EC2 instance, the instance will stop.
- Terminate Option: There is an option to set the shutdown behavior to terminate. This means that when a shutdown command is issued from within the OS, the EC2 instance will terminate and be permanently deleted.
- AWS Console vs. OS Shutdown: The terminate option is only applicable when the shutdown is initiated from within the EC2 instance's OS. Stopping the instance via the AWS console will not terminate it.
- CLI Attribute: The attribute for setting the shutdown behavior is
InstanceInitiatedShutdownBehavior.
- Termination Protection: EC2 instances can have termination protection enabled to prevent accidental termination from the console or CLI.
- Exam Tip: Even if termination protection is enabled, if the shutdown behavior is set to terminate and a shutdown command is issued from the OS, the instance will still be terminated.
Conclusion
- It is important to understand the difference between stopping and terminating an EC2 instance and the implications of the shutdown behavior settings.
- Termination protection is a useful feature to prevent accidental deletion but does not override the shutdown behavior set within the instance's operating system.
- Always verify the shutdown behavior and termination protection settings to ensure they align with your intended use case for the EC2 instance.