title: Configuring Fabric For EC2
body: <p>I am trying to create a fabfile.py so that I can deploy on EC2. I have the following in my fabfile.py:</p>
  
  <pre><code>from __future__ import with_statement
  from fabric.api import *
  
  
  def ec2():
      env.hosts = ['111.111.111.111'] 
      env.user = 'ubuntu'
      env.key_filename = '/path/to/my/pem/key.pem'
  
  def run_ls():
      run('ls -alt')
  </code></pre>
  
  <p>'111.111.111.111' is the elastic ip of my instance, and i alway login with ubuntu, not root.
  when i run the following command</p>
  
  <pre><code>fab ec2 run_ls
  </code></pre>
  
  <p>i see the following output:</p>
  
  <pre><code>[111.111.111.111] Executing task 'run_ls'
  [111.111.111.111] run: ls -alt
  
  Fatal error: Host key for 111.111.111.111 did not match pre-existing key! Server's key was changed recently, or possible man-in-the-middle attack.
  
  Aborting.
  </code></pre>
  
  <p>Not sure what is going on, but I can't find to seem any great tutorials on using fabric on ec2, and I do not know how that is possible.</p>
  
  <p>Thanks</p>
  
  <h2>Update:</h2>
  
  <p>Looks like</p>
  
  <pre><code>env.hosts = ['111.111.111.111'] 
  </code></pre>
  
  <p>is not valid, you need to use the actually URL</p>
  
  <pre><code>env.hosts = ['mywebsite.com'] 
  </code></pre>
  
  <p>which fixed my issue</p>