Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

I am trying to create a so that I can deploy on EC2. I have the following in my

from __future__ import with_statement

from fabric.api import *

def ec2():

    env.hosts = [''] 

    env.user = 'ubuntu'

    env.key_filename = '/path/to/my/pem/key.pem'

def run_ls():

    run('ls -alt')

'' is the elastic IP of my instance, and I always log in with ubuntu, not root. when I run the following command

fab ec2 run_ls

I see the following output:

[] Executing task 'run_ls'

[] run: ls -alt

Fatal error: Host key for did not match the pre-existing key! Server's key was changed recently, or possible man-in-the-middle attack.


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.

Looks like

env.hosts = [''] 

is not valid, you need to use the actually URL

env.hosts = [''] 

which fixed my issue

1 Answer

0 votes
by (44.4k points)

The elastic IP has to be attached to the instance. Also, it is working when we pass an array:

env.user = "ubuntu"

env.key_filename = ["my_key.pem",]

Also, try using the public DNS name of the instance:


    'prod': [''],


Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories