首页 > 解决方案 > 通过 Lambda 重新启动服务器后 AWS Win 任务未运行

问题描述

我编写了一个简单的任务计划来关闭 AWS Windows 服务器和一个简单的 Lambda 代码来打开停止的实例,请参阅代码:

import time
import json
import boto3


def lambda_handler(event, context):
    # boto3 client
    client = boto3.client('ec2')
    ssm = boto3.client('ssm')

    # getting instance information
    describeInstance = client.describe_instances()
    #print("eddie", describeInstance["Reservations"][0]["Instances"][0]["State"]["Name"])

    InstanceId = []
    # fetchin instance id of the running instances
    for i in describeInstance['Reservations']:
        for instance in i['Instances']:
            if instance["State"]["Name"] == "stopped":
                InstanceId.append(instance['InstanceId'])


    client.start_instances(InstanceIds=InstanceId)

    """looping through instance ids
    for instanceid in InstanceId:
        # command to be executed on instance
        client.start_instances(InstanceIds=InstanceId)
        print(output)"""

    return {
        'statusCode': 200,
        'body': json.dumps('Thanks from Srce Cde!')
    }

我的任务调度程序上有几个运行 Python 脚本的任务,但是在激活之后,即使服务器正在运行,这些任务也没有运行。

请注意,我已尝试在所有这些上设置“无论是否登录都运行”,但收到与这些任务的权限相关的(0x1)错误

有谁知道如何解决这个问题?有没有其他方法可以在夜间关闭和打开 EC2 AWS win 服务器以节省账单

感谢一百万的帮助者

谢谢,埃迪·阿布拉莫夫

标签: amazon-web-servicesamazon-ec2aws-lambdascheduled-taskstaskscheduler

解决方案


推荐阅读