我需要在lambda AWS上运行以下函数:
def subset_sum(numbers, target, partial=[]):
s = sum(partial)
# check if the partial sum is equals to target
if s == target:
print("sum(%s)=%s" % (partial, target))
if s >= target:
return # if we reach the number why bother to continue
for i in range(len(numbers)):
n = numbers[i]
remaining = numbers[i + 1:]
subset_sum(remaining, target, partial + [n])
if __name__ == "__main__":
subset_sum([1,2,3], 5)
但是出现以下错误,我无法解决:
{
"errorMessage": "'>=' not supported between instances of 'int' and 'LambdaContext'",
"errorType": "TypeError",
"stackTrace": [
[
"/var/task/lambda_function.py",
7,
"subset_sum",
"if s >= target:"
]
]
}
由于我在Lambda上运行,原始函数有更多的值需要很长时间。
在使用py subset_sum.py的计算机上,它可以正常工作。
答案 0 :(得分:0)
处理函数有2个参数事件和上下文
def handler_name(event, context):
...
return some_value
http://docs.aws.amazon.com/lambda/latest/dg/python-programming-model-handler-types.html