user data scripts fails without giving reason

Question:

I am starting a Amazon Linux instance (ami-fb8e9292) using the web console, pasting data into the user data box to run a script upon startup. If I use the example given by amazon to start a web server, it works. But when I run my own script (also a #!/bin/bash script), it does not get run.

If I look in var/log/cloud-init.log, it gives no useful information on the topic:

If I ssh into the instance and sudo su and execute the shell script directly:

then it runs fine. Also, it works if I emulate the way cloud-init runs it:

Using either of those methods, if I intentionally introduce errors into the script then it produces error messages. How can I debug the selective absence of useful debugging output?

Answer:

I’m not sure if this is going to be the case for everyone, but I was having this issue and was able to fix it by changing my first line from this:

to just this:

Of course, now my script is failing and I have no idea how far it’s getting, but at least I got past it not running it at. 🙂

Leave a Reply