Python 3.x 无法从Amazon Connect调用Python Lambda函数

Python 3.x 无法从Amazon Connect调用Python Lambda函数,python-3.x,amazon-web-services,aws-lambda,amazon-connect,Python 3.x,Amazon Web Services,Aws Lambda,Amazon Connect,我一直试图从AmazonConnect调用Python中的简单lambda函数,但未能做到这一点。 错误:Lambda函数返回错误 功能: 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_time

我一直试图从AmazonConnect调用Python中的简单lambda函数,但未能做到这一点。 错误:Lambda函数返回错误

功能:

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函数产生错误。

您的函数需要返回一个具有多个或多个属性的对象,用于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_打印标识符访问联系人流后续块中的响应,该标识符将返回“hello”