0

我一直在尝试从 Amazon Connect 调用 Python 中的简单 lambda 函数,但无法这样做。错误:The Lambda Function Returned An Error.

功能:

import os
def lambda_handler(event, context):
what_to_print = 'hello'
how_many_times =1
# make sure what_to_print and how_many_times values exist
if what_to_print and how_many_times > 0:
    for i in range(0, how_many_times):
        # formatted string literals are new in Python 3.6
        print(f"what_to_print: {what_to_print}.")
    return what_to_print
return None`

现在,每当我尝试使用 CLI 调用此函数时aws lambda invoke --function-name get_info outputfile.txt,它都会成功运行并产生正确的输出。现在奇怪的部分来自 Amazon Connect 我能够轻松调用任何 node.js lambda 函数,只有 Python 函数会产生错误。

4

1 回答 1

1

您的函数需要返回一个具有多个属性的对象,以便 Amazon Connect 将其视为有效响应,因为它会尝试遍历响应对象的属性。在您的代码中,您只需返回一个字符串,该字符串作为正常输出的一部分打印良好,但不是 Amazon Connect 在响应中预期的内容。如果您将代码更改为类似的内容,您将能够将其与 Amazon Connect 一起使用。

import os
def lambda_handler(event, context):
    what_to_print = 'hello'
    how_many_times =1
    resp = {}
    # make sure what_to_print and how_many_times values exist
    if what_to_print and how_many_times > 0:
        for i in range(0, how_many_times):
            # formatted string literals are new in Python 3.6
            print(f"what_to_print: {what_to_print}.")
            resp["what_to_print"] = what_to_print
    return resp

然后,您可以使用$.External.what_to_print identifier返回“hello”的 来访问联系流的后续块中的响应。

于 2018-05-31T02:50:51.427 回答