【问题标题】:Not able to invoke Python Lambda function from Amazon Connect无法从 Amazon Connect 调用 Python Lambda 函数
【发布时间】:2018-05-30 02:50:35
【问题描述】:

我一直在尝试从 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 函数会产生错误。

【问题讨论】:

    标签: python-3.x amazon-web-services aws-lambda amazon-connect


    【解决方案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”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 2021-03-26
      • 1970-01-01
      • 2016-02-13
      • 2017-03-09
      相关资源
      最近更新 更多