我每天计划在晚上8点使用chalice和lambda函数关闭ec2实例。
我已经配置了圣杯,但无法使用圣杯触发或集成python脚本
导入boto3 #创建会话以连接到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])
我想停止使用圣杯的实例
答案 0 :(得分:0)
AWS Instance Scheduler完成您要寻找的工作。我们已经使用了几个月。它按预期工作。您可以检查以下参考:https://aws.amazon.com/premiumsupport/knowledge-center/stop-start-instance-scheduler/