0

Amazon Connect から Python で単純なラムダ関数を呼び出そうとしましたが、実行できませんでした。エラー: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からのもので、エラーを生成するPython関数のみを簡単にnode.jsラムダ関数を呼び出すことができます。

4

1 に答える 1

1

関数は、応答オブジェクトのプロパティを反復しようとするため、Amazon Connect が有効な応答と見なすために、1 つ以上のプロパティを持つオブジェクトを返す必要があります。コードでは、通常の出力の一部として正常に出力される文字列を返すだけですが、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 に答える