【发布时间】:2018-01-09 19:41:51
【问题描述】:
我在 AWS 中创建了一个 python Lambda 函数,以根据部署到它们的 TAG 启动一些 EC2 实例。它检查实例是否已停止并仅在它们上运行。
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 运行时,并且我使用的角色与其他可以正常启动服务器的函数相同(仅基于时间)。
你能建议吗?谢谢!
【问题讨论】:
-
这可能有助于您理解错误:stackoverflow.com/questions/23944657/…
-
ec2.instances.filter(...)
标签: python amazon-web-services amazon-ec2 aws-lambda