1

我每天晚上 8 点使用 chalice 和 lambda 函数安排 ec2 实例关闭。

我已经配置了圣杯,但无法使用圣杯触发或集成 python 脚本

import boto3 #creating session 以连接到 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])

我想使用圣杯停止实例

4

1 回答 1

0

AWS Instance Scheduler 执行您正在寻找的工作。我们已经使用了几个月。它按预期工作。您可以查看此参考:https ://aws.amazon.com/premiumsupport/knowledge-center/stop-start-instance-scheduler/

于 2019-09-04T18:07:38.450 回答