title: os.system('sudo shutdown now -P') doesn't work with cloud-init
body: <p>I want to launch an Amazon EC2 instance programmatically, use cloud-init to execute a Python script, then have this same script terminate the instance. Everything works fine, except for the self-termination part. I've tried this:</p>
  
  <pre><code>os.system('sudo shutdown now -P')
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>os.system('sudo -n shutdown now -P')
  </code></pre>
  
  <p>And also this:</p>
  
  <pre><code>os.popen('sudo -S shutdown now -P')
  </code></pre>
  
  <p>No good. In all cases the <code>/var/log/cloud-init.log</code> file shows <code>sudo: sorry, you must have a tty to run sudo</code>.</p>
  
  <p>Apparently commenting out the <code>Default requiretty</code> line on <code>/etc/sudoers</code> does the trick, but I want to do things programmatically, so I guess that's not an option here (and it probably would require root privileges as well, which takes us back to square one).</p>
  
  <p>I suppose I could use a multi-part cloud-init script - say, follow the Python script with a bash script that does the self-termination. But surely there must be a way to solve this from within Python?</p>
  
  <p>(Amazon Linux. Python 2.7.5. Boto 2.23)</p>