1

I am scheduling ec2 instance shutdown everyday at 8 PM using chalice and lambda function.

I have configured the chalice but not able to trigger or integrate python script using chalice

import boto3 #creating session to connect to aws

#defining instances to be started or stopped
myins = ['i-043ae2fbfc26d423f','i-0df3f5ead69c6428c','i-0bac8502574c0cf1d','i-02e866c4c922f1e27','i-0f8a5591a7704f98e','i-08319c36611d11fa1','i-047fc5fc780935635']
#starting ec2 instances if stopped
ec2 = boto3.resource('ec2')
ec2client = boto3.client('ec2')
  for instance in ec2.instances.all():
      for i in myins:
       if i == instance.id and instance.state['Name'] == "running":
       ec2client.stop_instances(InstanceIds=[i])

I want to stop instance using chalice

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
monica
  • 11
  • 3
  • Chalice will help you to deploy your function on AWS lambda but you need cloud watch event rules to trigger your lambda at 8 PM. – mohit Sep 04 '19 at 18:11
  • Thanks for the information john , here i tried using zappa – monica Sep 10 '19 at 10:27

1 Answers1

0

AWS Instance Scheduler does the job that you are looking for. We have used it for several months. It works as expected. You may check this reference: https://aws.amazon.com/premiumsupport/knowledge-center/stop-start-instance-scheduler/

Bryan
  • 400
  • 1
  • 3
  • 15