用于检查URL运行状况的Python Lambda

问题描述 投票:0回答:1

我编写了一个小函数,但是当我执行它时,只有列表中的最后一个URL传递给function。请对此进行更正。

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:
        return 'Website is alive!'
    else:
        sns_client = boto3.client('sns')
        sns_client.publish(
        TopicArn = topicArnCode,
        Subject = 'Website is not reachable ' + x,
        Message = 'Website: ' + x + ' is down\n')
        return 'Website is dead'
python lambda
1个回答
1
投票

这是缩进错字:

© www.soinside.com 2019 - 2024. All rights reserved.