title: User-data scripts is not running on my custom AMI, but working in standard Amazon linux
body: <p>I searched a lot of topic about "user-data script is not working" in these few days, but until now, I haven't gotten any idea about my case yet, please help me to figure out what happened, thanks a lot!</p>
  
  <p>According to AWS <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html" rel="noreferrer">User-data</a> explanation:</p>
  
  <blockquote>
    <p>When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts.</p>
  </blockquote>
  
  <p>So I tried to pass my own user-data when instance launch, this is my user-data:</p>
  
  <pre><code>\#!/bin/bash
  
  echo 'test' &gt; /home/ec2-user/user-script-output.txt
  </code></pre>
  
  <p>But there is no file in this path: <code>/home/ec2-user/user-script-output.txt</code></p>
  
  <p>I checked <code>/var/lib/cloud/instance/user-data.txt</code>, the file is exist and same as my user-data script.</p>
  
  <p>Also I checked the log in <code>/var/log/cloud-init.log</code>, there is no error message.</p>
  
  <p>But the user-data script is working if I launch an new instance with Amazon linux(2014.09.01), but I'm not sure what difference between my AMI (based on Amazon linux) and Amazon linux.</p>
  
  <p>The only different part I saw is if I run this script:</p>
  
  <pre><code>sudo yum list installed | grep cloud-init
  </code></pre>
  
  <p>My AMI:</p>
  
  <blockquote>
    <p>cloud-init.noarch                    0.7.2-8.33.amzn1              @amzn-main </p>
  </blockquote>
  
  <p>Amazon linux:</p>
  
  <blockquote>
    <p>cloud-init.noarch                     0.7.2-8.33.amzn1             installed    </p>
  </blockquote>
  
  <p>I'm not sure this is the reason?</p>
  
  <p>If you need more information, I'm glad to provide, please let me know what happened in my own AMI and how to fix it?</p>
  
  <p>many thanks</p>
  
  <p><strong>Update</strong></p>
  
  <p>Just found an answer from this <a href="https://stackoverflow.com/questions/25497689/how-to-make-ec2-user-data-work-on-freshly-built-ami-made-with-packer">post</a>,</p>
  
  <p>If I add #cloud-boothook in the top of user-data file, it works!</p>
  
  <pre><code>#cloud-boothook
  #!/bin/bash
  echo 'test' &gt; /home/ec2-user/user-script-output.txt
  </code></pre>
  
  <p>But still not sure why.</p>