【发布时间】:2021-09-30 19:58:00
【问题描述】:
我是 DevOps 的初学者和编程的菜鸟。我被分配了一个任务来自动启动具有特定顺序的一组实例。在启动下一个服务之前检查其 Linux 服务的运行状况。
我找到了一个可以作为 lambda 函数运行的自动停止和启动 python 脚本,但我不知道如何按顺序启动实例并检查服务器服务的运行状况。
如果有什么可以帮助我或指导我如何做到这一点,我将不胜感激。
谢谢
import boto3
import request
import time
region = 'region'
instances = ['']
ec2 = boto3.client('ec2', region_name=region)
def Ec2Instance1(ec2start):
ec2.start_instances(InstanceIds=instances)
print('started your instances: ' + str(instances))
def lambda_handler(event, context):
websiteURL = ['https://example1.com','https://example2.com','https://example3.com']
topicArnCode = 'arn:aws:sns:ap-southeast-1:123:sample'
for x in websiteURL:
print (x)
r = requests.get(x,verify=False)
print (r)
if r.status_code == 200:
Ec2Instance1()
time.sleep(10)
elif r.status_code == 200:
Ec2Instance1()
else:
sns_client = boto3.client('sns')
sns_client.publish(
TopicArn = topicArnCode,
Subject = 'Website is not reachable ' + x,
Message = 'Website: ' + x + ' is down\n')
print('Website is dead')
【问题讨论】:
-
您如何定义“检查其 Linux 服务的健康状况”?
标签: python linux amazon-ec2 aws-lambda devops