User data bash script to start services in EC2 instance not executing

Solution 1:

From Configuring Instances with User Data

When you specify user data, note the following:

  • User data is treated as opaque data: what you give is what you get back. It is up to the instance to be able to interpret it.
  • User data is limited to 16 KB. This limit applies to the data in raw form, not base64-encoded form.
  • User data must be base64-encoded. The Amazon EC2 console can perform the base64 encoding for you or accept base64-encoded input.
  • User data must be decoded when you retrieve it. The data is decoded when you retrieve it using instance metadata and the console.
  • User data is executed only at launch. If you stop an instance, modify the user data, and start the instance, the new user data is not executed automatically

Userdata only runs on the instance launch. Its purpose is to run once, to allow for one-time server configuration tasks before the instance is put into service.

Do you want the software installation process to run each time on reboot? If you want to start a process on each reboot, then look into /etc/rc.local.