0

I have 2 Lambda Functions [A and B]. Function A does a computation and returns 2 strings. 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.

Function A1 (two strings returned):

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):

def handler(event, context):

    string = "This is a string"

    return string

Calling A1 in another Lambda Function:

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:

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? Invoking A1/A2 on their own gives expected returns.

Thanks!

6
  • You are calling a Lambda function from another Lambda function by using functionA1(event, context)? Shouldn't you be using the Invoke() command? Commented Sep 25, 2018 at 22:50
  • @JohnRotenstein I am using the Invoke() command - above was just for demo and not precise code Commented Sep 25, 2018 at 23:07
  • "Not precise code" does not lend itself to accurate solutions; see stackoverflow.com/help/mcve. The problem is that you seem to be overlooking the fact that everything coming out of a Lambda function invocation should be JSON that needs to be decoded. Commented Sep 26, 2018 at 0:48
  • payload = {} #blank payload Commented Sep 26, 2018 at 9:49
  • payload['string'] = "This is a string" Commented Sep 26, 2018 at 9:50

1 Answer 1

1

Found the problem! Decoding needed before reading the JSON response:

load = json.loads(response['Payload'].read().decode("utf-8"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.