1
通过运行此代码,我只想停止使用标记Class:ClassB的insances。 测试功能后,它会关闭所有实例:即使配置了过滤器,AWS Lambda函数也会停止所有实例
import boto3
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
filters = [{'Name': 'tag:Class', 'Values':['ClassB']},{'Name': 'instance-state-name', 'Values': ['running']}]
instances=ec2.instances.filter(Filters=filters)
for instance in instances:
ec2.instances.stop()
print 'stop your instances: ' + str(instances)
问题出在哪里?
做你的情况有标签?代码看起来不错。 – helloV
@helloV不,我有两个instaces只有这个标签!是的,这很令人惊讶 – JavaQueen