基于标签启动EC2实例的Lambda函数
问题描述:
我已经在AWS中创建了一个Python Lambda函数,用于根据部署到它们的TAG启动一些EC2实例。它检查实例是否停止并且只运行它们。基于标签启动EC2实例的Lambda函数
import boto3
import logging
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
filters = [{
'Name': 'tag:STARTUP',
'Values': ['YES']
},
{
'Name': 'instance-state-name',
'Values': ['stopped']
}]
instances = instances.filter(Filters=filters)
stoppedInstances = [instance.id for instance in instances]
if len(stoppedInstances) > 0:
startingUp = instances.filter(instances).start()
当我尝试运行它,我得到以下错误:
START RequestId: XXX Version: $LATEST
filter() takes 1 positional argument but 2 were given: TypeError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 17, in lambda_handler
startingUp = ec2.instances.filter(instances).start()
TypeError: filter() takes 1 positional argument but 2 were given
虽然到处看filter变量能够处理多个参数,但不知何故,我只能够使用一?
我正在使用Python 3.6运行时,并且使用与其他正常工作的函数(仅基于时间)启动服务器相同的角色。
你能提供建议吗?谢谢!
答
这就是@最后一行!谢谢您的评论说,向我指出了正确的方向:)
startingUp = ec2.instances.filter(InstanceIds=stoppedInstances).start()
这可以帮助你理解错误:https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-参数 - 但是2 - 给出/ 23944658 – HakRo
ec2.instances.filter(...) – jarmod