简体   繁体   中英

python: How to run command on local machine from an EC2 instance

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 abcd) and tried ssh abcd 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

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, ie 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? Ie SSH from local machine to EC2 instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM