EC2 – How to Make User Data Script Run Again on Startup

amazon ec2cloud-init

After cloud-init runs a user data script on the first boot of an EC2 instance, a state file is presumably written so that cloud-init won't run the script again on subsequent reboots. There are cases where I'd like to delete this state file so that the user data script will run again. Where is it?

Best Answer

rm /var/lib/cloud/instances/*/sem/config_scripts_user

Confirmed working on:

  • CentOS 7.4
  • Ubuntu 14.04
  • Ubuntu 16.04

For the sake of completeness, if you have a situation where you care to keep track of the fact/possibility that this AMI [had a parent AMI that ...] and they all ran cloud-init user data, you can delete only the current semaphore.

rm /var/lib/cloud/instance/sem/config_scripts_user