使用python重启后检查AWS实例是否启动 [英] To check whether AWS instance is up after reboot using python

查看:106
本文介绍了使用python重启后检查AWS实例是否启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使用boto3或其他方式检查AWS实例是否最终在python中出现.运行状态不会在重新启动阶段和最终启动阶段之间进行区分.

Is there a way to check if an AWS instance has finally come up in python either using boto3 or otherwise. The running state doesnt differentiate between rebooting and finally up phase.

推荐答案

如果只想检查远程端口是否打开,则可以使用内置的

If you just want to check that a remote port is open you could use the built-in socket package.

这里是此答案的快速修改,用于等待远程端口打开:

Here's a quick modification of this answer of waiting for a remote port to open:

import socket
import time

def wait_for_socket(host, port, retries, retry_delay=30):
    retry_count = 0
    while retry_count <= retries:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = sock.connect_ex((host, port))
        sock.close()
        if result == 0:
            print "Port is open"
            break
        else:
            print "Port is not open, retrying..."
            time.sleep(retry_delay)

这篇关于使用python重启后检查AWS实例是否启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆