[cs615asa] Question about ssh in python

Nicholas Bevacqua nbevacqu at stevens.edu
Mon Mar 31 03:10:49 EDT 2014


I had similar issues. Depending on Amazon, it can take far longer than 45
seconds for the instance to be ready. Your best approach is to do what I
did and fetch both the system status and the instance status. When both are
'Status:ok', then it is safe to connect. You can do this in boto like so:

status = conn.get_all_instance_status(instance_ids=[instance.id])[0]
currentSystemStatus = str(status.system_status)
currentInstanceStatus = str(status.instance_status)
if (currentSystemStatus != 'Status:ok') or (currentInstanceStatus !=
'Status:ok'):
    ...

-Nick Bevacqua


On Sun, Mar 30, 2014 at 11:44 PM, Paul-Anthony Dudzinski <
pdudzins at stevens.edu> wrote:

> Can you connect via ssh BEFORE you pass that command programattically? If
> that is the case you might have a problem with the filepath expansion of
> "~", otherwise if this only works after you may just not be able to connect
> yet.
>
>
> On Sun, Mar 30, 2014 at 11:32 PM, Dainong Ma <dma2 at stevens.edu> wrote:
>
>>
>> Hello everyone, I have a problem using python to connect ec2-instance.
>> I write this in python so that I can connect to ec2-instance but I get a
>> connection refused. I can be sure that I use correct KeyPair and
>> SecurityGroup. And also I let my program time.sleep(45)
>> after creating instance.
>>
>>            command ="ssh -i %s -o StrictHostKeyChecking=no %s@%s"%(KEYPAIR_LOCATION,
>> INSTANCE_LOGIN_USR, EC2_HOST)
>> output: mountvolume (65280, 'ssh: connect to host
>> ec2-54-208-77-230.compute-1.amazonaws.com port 22: Connection refused\r')
>>
>> But when I ssh from command line right after that moment:  ssh -i
>> ~/.ssh/ec2backup-keypair.pem -o StrictHostKeyChecking=no
>> ec2-user at ec2-54-208-77-230.compute-1.amazonaws.com, I can connect it.
>>
>> Does that mean I can not write ssh command in python like that?
>>
>> _______________________________________________
>> cs615asa mailing list
>> cs615asa at lists.stevens.edu
>> https://lists.stevens.edu/mailman/listinfo/cs615asa
>>
>>
>
> _______________________________________________
> cs615asa mailing list
> cs615asa at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs615asa
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.stevens.edu/mailman/private/cs615asa/attachments/20140331/b67c5c03/attachment.html>


More information about the cs615asa mailing list