I am using Python to launch an ec2 instance
, after I get "running"
state of my instance, I am trying to SCP
a shell script and run it via ssh.
I am getting the following error
"ssh: connect to host ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com port 22: Connection refused"
When I check in the console, the Status check is "Initializing"
, once It changes "2/2 checks passed"
, I am able to ssh
or run any script.
Is there any way I can get the "status check" via python boto API
?
I am using Python 2.7.5+, boto 2.19.0
Thanks in advance.
Simple way is to check the port 22 of the newly created instance is reachable or not by using socket
module
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('hostname', 22))
print "Port 22 reachable"
except socket.error as e:
print "Error on connect: %s" % e
s.close()
When you will able to reach the port 22 then you can invoke ssh to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With