我有2个Lambda函数[A和B]。函数A进行计算并返回2个字符串。请注意,我也尝试过返回一个字符串。单独调用该函数时,返回的是正确的预期字符串。
如果我在函数B内调用函数A,则返回的是正确的字符串,但每侧都添加了字符。
函数A1(返回了两个字符串):
def handler(event, context):
strings = {
"first_string": "This is the first string",
"second_string": "This is the second string"
}
return strings
函数A2(返回一个字符串):
def handler(event, context):
string = "This is a string"
return string
在另一个Lambda函数中调用A1:
return_strings = functionA1(event, context)
print(return_strings[0])
print(return_strings[1])
>>> 341 #expected This is the first string
>>> 8 #expected This is the second string
在另一个Lambda函数中调用A2:
return functionA2(event, context)
>>> b'\"This is a string\"' #expected This is a string
任何想法都可能在返回值中进行编码-与从另一个Lambda函数进行调用有关吗?单独调用A1 / A2可以得到预期的回报。
谢谢!
答案 0 :(得分:0)
发现了问题!在读取JSON响应之前需要解码:
load = json.loads(response['Payload'].read().decode("utf-8"))