I have two databases one on my local machine and one on my amazon ec2 instance.Now what I
do is I run a python program on my local machine which makes changes to the databse on my local machine.I want these changes to be reflected onto the database on amazon ec2 instance,
periodically.I want to do this in python.A script that logs onto the amazon server establishes a connection with the database there and makes the changes.
I came across some modules like pexcept
,fabric
and paramiko
.But I am struggling with the
key authentication.
The way I ssh from my terminal is ssh -i my_rsa_file.pem username@ip_address
.There is no password.How do I go about this ??
Also I want to know whether simply using Popen
in subprocess
to execute the login command work ?
Asked
Active
Viewed 1,053 times
0

sasha sami
- 525
- 1
- 10
- 24
-
Have you looked at these articles? [http://stackoverflow.com/questions/6569833/ssh-module-for-python][1] [http://stackoverflow.com/questions/946946/how-to-execute-a-process-remotely-using-python][2] [1]: http://stackoverflow.com/questions/6569833/ssh-module-for-python [2]: http://stackoverflow.com/questions/946946/how-to-execute-a-process-remotely-using-python – derigible Jul 18 '13 at 22:10
1 Answers
0
The Boto EC2 documentation here describes the EC2 instance object, of which "key_pair" is an attribute. Look about 3/4 of the way down, under "boto.ec2.instance".
http://boto.readthedocs.org/en/latest/ref/ec2.html
So, e.g., you could run some instances as follows, and then store the first instance as "inst":
reservation = conn.run_instances(...)
inst = reservation.instances[0]
To retrieve your key-pair name as a unicode string, just use:
kp_name = inst.key_name
You can then retrieve the corresponding Boto object using get_key_pair:
kp_obj = conn.get_key_pair(kp_name)
Of course, this is a silly example, since I would have needed my key pair name to run_instances in the first place. May you find a more fruitful application!

Nathan Gould
- 7,995
- 2
- 17
- 15