坚持与Amazon EC2实例的状态检查 [英] stuck with status check of amazon ec2 instance
问题描述
我使用Python来启动EC2实例后,我得到跑我的实例的状态,我想SCP一个shell脚本,并通过ssh运行它。
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.
我收到以下错误
SSH:连接到主机ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com端口22:连接被拒绝
"ssh: connect to host ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com port 22: Connection refused"
当我检查在控制台中,状态检查是初始化,一旦它改变了2/2检查合格,我能SSH或运行任何脚本。
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.
有什么办法,我可以通过Python博托API获得状态检查?
Is there any way I can get the "status check" via python boto API?
我使用Python 2.7.5+, 博托2.19.0
I am using Python 2.7.5+, boto 2.19.0
在此先感谢。
推荐答案
简单的方法是使用检查口新创建的实例的22可达与否插槽
模块
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()
当你将能够达到22端口,那么你可以调用ssh来了。
When you will able to reach the port 22 then you can invoke ssh to it.
这篇关于坚持与Amazon EC2实例的状态检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!