title: aws ec2 run-instances: base64 encoded user-data blob is ignored
body: <p>My base64 encoded user-data is ignored while running <code>aws ec2 run-instances</code> command.</p>
  
  <p>Here is my user data:</p>
  
  <pre><code>$ cat user-data.sh 
  #!/bin/bash
  cat &gt;&gt; /var/tmp/user-data-testing &lt;&lt;EOF
  this is test line added at $(date)
  EOF
  </code></pre>
  
  <p>here is base64 blob of above script:</p>
  
  <pre><code>IyEvYmluL2Jhc2gKY2F0ID4+IC92YXIvdG1wL3VzZXItZGF0YS10ZXN0aW5nIDw8RU9GCnRoaXMgaXMgdGVzdCBsaW5lIGFkZGVkIGF0ICQoZGF0ZSkKRU9GCg==
  </code></pre>
  
  <p>Now, My below command does read the user-data fine:</p>
  
  <pre><code>aws ec2 run-instances --image-id ami-8635a9b6 --instance-type t1.micro --placement AvailabilityZone=us-west-2a --security-groups quicklaunch-1 --key-name devops --user-data file://user-data.sh
  </code></pre>
  
  <p>I do see that file <code>/var/tmp/user-data-testing</code> is created.</p>
  
  <p>However, when I try to pass-in user-data as a base64 encoded blob as below, then it gets ignored:</p>
  
  <pre><code>aws ec2 run-instances --image-id ami-8635a9b6 --instance-type t1.micro --placement AvailabilityZone=us-west-2a --security-groups quicklaunch-1 --key-name devops --user-data IyEvYmluL2Jhc2gKY2F0ID4+IC92YXIvdG1wL3VzZXItZGF0YS10ZXN0aW5nIDw8RU9GCnRoaXMgaXMgdGVzdCBsaW5lIGFkZGVkIGF0ICQoZGF0ZSkKRU9GCg==
  </code></pre>
  
  <p>Now, I do not see the file <code>/var/tmp/user-data-testing</code> created.</p>
  
  <p>Also, I know that my base64 blob is healthy as I can decode it fine:</p>
  
  <pre><code>$ base64 --decode &lt;&lt;&lt; IyEvYmluL2Jhc2gKY2F0ID4+IC92YXIvdG1wL3VzZXItZGF0YS10ZXN0aW5nIDw8RU9GCnRoaXMgaXMgdGVzdCBsaW5lIGFkZGVkIGF0ICQoZGF0ZSkKRU9GCg==
  #!/bin/bash
  cat &gt;&gt; /var/tmp/user-data-testing &lt;&lt;EOF
  this is test line added at $(date)
  EOF
  </code></pre>
  
  <p>However, I do see that instance metadata has my user data in base64 format:</p>
  
  <pre><code>$ curl -L http://169.254.169.254/latest/user-data/
  IyEvYmluL2Jhc2gKY2F0ID4+IC92YXIvdG1wL3VzZXItZGF0YS10ZXN0aW5nIDw8RU9GCnRoaXMgaXMgdGVzdCBsaW5lIGFkZGVkIGF0ICQoZGF0ZSkKRU9GCg==
  </code></pre>
  
  <p><strong>So, what am I doing wrong in using base64 user-data blob?</strong> </p>
  
  <p>My instance meta-data is aware of it but seems like it is not really being executed (or decoded and executed) at the time of instance launch. </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>If I pass the same base64 blob via AWS Console while launching the instance, It works. So seems like something is wrong in the way I am using it along with <code>AWS-CLI</code>.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I just tried the same base64 blob with my ruby code as below and it worked as well:</p>
  
  <pre><code>ec2 = Aws::EC2.new
  resp = ec2.run_instances(
      min_count: 1,
      max_count: 1,
      image_id: 'ami-8635a9b6',
      instance_type: 't1.micro',
      placement: {
        availability_zone: 'us-west-2a'
      },
      security_groups: ['quicklaunch-1'],
      key_name: 'devops',
      user_data: 'IyEvYmluL2Jhc2gKY2F0ID4+IC92YXIvdG1wL3VzZXItZGF0YS10ZXN0aW5nIDw8RU9GCnRoaXMgaXMgdGVzdCBsaW5lIGFkZGVkIGF0ICQoZGF0ZSkKRU9GCg=='
  )
  </code></pre>
  
  <p>So, then WTF is wrong my implementation of <code>AWS-CLI</code> ?</p>