This post shows how to achieve the later using Packer by HashiCorp.TL;DR I don't like to be woken up at 3 AM to restart a server, especially if hardware of the cloud provider running your instances decides to misbehave. Back in 2015 AWS made it possible to automatically recover EC2 instances from issues like:

Loss of network connectivity

Loss of system power

Software issues on the physical host

Hardware issues on the physical host that impact network reachability

All you have to do is create a CloudWatch alarm for the metric StatusCheckFailed_System and choose the Recover this instance action.

One limitations is not mentioned in the docs or troubleshooting guide at the time of this writing, however - you cannot auto-recover instance created from AMI defining ephemeral (a.k.a. instance store) block device mappings. It doesn't matter whether you actually attach ephemeral volumes to your instance, or that instance family doesn't support instance store volumes (M4). If your AMI defines ephemeral devices, auto-recovery fails.

So if you're using official Ubuntu AMIs, you have a problem...

Let's examine the latest AMI of Ubuntu Trusty server from Canonical (HVM, EBS backed, x86_64). Run the following command (feel free to replace --region value with one of your preference):