Back

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

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

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')

'111.111.111.111' 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:

[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 the pre-existing key! Server's key was changed recently, or possible man-in-the-middle attack.

Aborting.

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 = ['111.111.111.111'] 

is not valid, you need to use the actually URL

env.hosts = ['mywebsite.com'] 

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:

env.roledefs.update({

    'prod': ['ec2-52-14-72-225.us-west-1.compute.amazonaws.com'],

})

Related questions

Want to get 50% Hike on your Salary?

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

Browse Categories

...