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