[英]AWS Lambda function appending characters in return
I have 2 Lambda Functions [A and B]. 我有2个Lambda函数[A和B]。 Function A does a computation and returns 2 strings. 函数A进行计算并返回2个字符串。 Note that I've also tried returning one string. 请注意,我也尝试过返回一个字符串。 When the function is called alone, the return is the correct expected string. 当单独调用该函数时,返回的是正确的预期字符串。
If I call function A inside function B, the return is the correct string but with characters added to each side. 如果我在函数B内调用函数A,则返回的是正确的字符串,但在每一侧都添加了字符。
Function A1 (two strings returned): 函数A1(返回两个字符串):
def handler(event, context):
strings = {
"first_string": "This is the first string",
"second_string": "This is the second string"
}
return strings
Function A2 (one string returned): 函数A2(返回一个字符串):
def handler(event, context):
string = "This is a string"
return string
Calling A1 in another Lambda Function: 在另一个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
Calling A2 in another Lambda function: 在另一个Lambda函数中调用A2:
return functionA2(event, context)
>>> b'\"This is a string\"' #expected This is a string
Any idea what might be encoded in the returns - is it related to calling from another Lambda function? 知道返回中可能会编码什么-与从另一个Lambda函数进行调用有关吗? Invoking A1/A2 on their own gives expected returns. 单独调用A1 / A2可获得预期收益。
Thanks! 谢谢!
Found the problem! 发现了问题! Decoding needed before reading the JSON response: 在读取JSON响应之前需要解码:
load = json.loads(response['Payload'].read().decode("utf-8"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.