I have coded a simple task scedule that turns the AWS Windows server off and a simple Lambda code to turn the stopped instaces on, see code:
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!') } I have several tasks on my task scheduler that run Python scripts but after the activation those tasks arent running even when the server in running.
Note, I have tried to set "run whether logged on or not" on all of them but recived (0x1) errors related to privileges on those tasks
Does anyone know how to solve this? Is there any other way to turn off and on EC2 AWS win server in night time to save on billing
Thanks a million for the helpers
Thanks, Eddie Abramov
https://stackoverflow.com/questions/65754733/aws-win-tasks-arent-running-after-server-restart-via-lambda January 17, 2021 at 05:07AM
没有评论:
发表评论