0

I am trying to automate the process of creating a postgres database from production dump using a python script. I am running this script on an EC2 instance that hosts an RoR app server.

I am able to create the DB using psychopg. But in the same script I want to do the following:

- do a deploy using capistrano from local machine

I came across paramiko - SSHClient in my research. I think it can be used. But I'm not sure how I can SSH from an EC2 instance to my local machine. I found out my IP(say a.b.c.d) and tried ssh a.b.c.d from the EC2 instance but it says:

ssh: connect to host a.b.c.d port 22: Connection refused

So my question is: - If this method (using paramiko) is correct, how can I set up a ssh connection from EC2 instance to my local machine OR If paramiko cannot achieve this, how can I run the deploy from my script that is on the EC2 instance

1
  • You can set a reverse ssh tunneling (google it ;)) Commented Oct 30, 2013 at 9:22

1 Answer 1

1

For one, paramiko is a bit low-level, you could try using Fabric, it will make a lot of things much easier.

Secondly, check whether your local machine is

  • accessible from the internet, i.e. has public IP address
  • running SSH (assuming you run *NIX-like OS, run ps -ef | grep sshd, if you see a process matching, then you should be able to connect)

Then, if you wanna automate a postgres DB creation on a EC2 instance, why do you need a connection from it to your local machine. Wouldn't it be more logical to reverse the process? I.e. SSH from local machine to EC2 instance.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for a very useful answer. Regarding your 3rd point : when I started writing the script, I didn't realize that I'll have to add the deploy feature. Since the DB was required in the EC2 I wrote the script in the EC2. Surprisingly the same script soesn't work on my local machine. Not sure why
Cause your local machine doesn't run SSH I suppose? Which OS are you using?
I just checked using the command you mentioned. Its showing running processes. I'm using ubuntu 12.04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.