我编写了一个简单的任务程序来关闭 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 服务器以节省账单
感谢一百万的帮助
谢谢, 埃迪·阿布拉莫夫