【问题标题】:AWS Lambda function stops all instances even the filter is configured即使配置了过滤器,AWS Lambda 函数也会停止所有实例
【发布时间】:2017-04-01 00:31:07
【问题描述】:

通过运行此代码,我只想停止带有标签 Class:ClassB 的实例。 测试功能后,关闭所有实例:

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 不,我只有两个带有这个标签的实例!是的,这很令人惊讶

标签: python amazon-web-services amazon-ec2 aws-lambda boto3


【解决方案1】:

应该是:

instance.stop()

您的代码不正确:

ec2.instances.stop()

【讨论】:

    猜你喜欢
    • 2018-05-16
    • 2021-07-13
    • 1970-01-01
    • 2019-08-28
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2016-12-13
    相关资源
    最近更新 更多