Is there a way to run a script on instance termination?
Not with any reliability. Amazon EC2 tries to shut an instance down cleanly (in which case normal system shutdown scripts will run), but there is only a short time available for things to happen and in some cases (hardware failure, for example) this does not happen. Since there is no entirely reliable way to ensure shutdown scripts run, it is best to have a strategy in place to deal with abnormal terminations.