I have been trying to invoke simple lambda function in Python from Amazon Connect but not able to do so.
Error: The Lambda Function Returned An Error.
Function:
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`
Now, whenever I try to invoke this function using CLI aws lambda invoke --function-name get_info outputfile.txt
.It runs successfully and produce the correct output.
Now the weird part is from Amazon Connect I am able to invoke any node.js lambda functions easily only Python functions producing an error.
Your function needs to return a object with more one or more property for Amazon Connect to consider it a valid response, because it tries to iterate through the properties of the response object. In your code, you just return a string, which prints fine as part of normal output, but is not what Amazon Connect anticipates in the response. If you change your code to something like this, you will be able to use it with 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
You can then access the response in subsequent blocks of your contact flow by using the $.External.what_to_print identifier
, which out return 'hello'.