32

I'm trying to call another lambda function from an existing lambda fucntion as below (python 2.7)

from __future__ import print_function
import boto3
import json

lambda_client = boto3.client('lambda')

def lambda_handler(event, context):

    invoke_response = lambda_client.invoke(FunctionName="teststack",
                                           InvocationType='RequestResponse'
                                           )
    print(invoke_response)

    return str(invoke_response)

I'm gettting the below response instead of an actual result. When I run teststack lambda invidually it works fine, but getting below response instead of "test" returned by the teststack Lambda function.

{u'Payload': <botocore.response.StreamingBody object at ****>, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '******', 'HTTPHeaders': {'x-amzn-requestid': '******', 'content-length': '155', 'x-amzn-remapped-content-length': '0', 'connection': 'keep-alive', 'date': 'Sun, 17 Jul 2016 21:02:01 GMT', 'content-type': 'application/json'}}, u'StatusCode': 200}
Gricey
  • 1,321
  • 1
  • 18
  • 38
shiv455
  • 7,384
  • 19
  • 54
  • 93
  • 1
    i got solution from this thread http://stackoverflow.com/questions/36784925/how-to-get-return-response-from-aws-lambda-function?rq=1 THanks!! – shiv455 Jul 18 '16 at 01:11
  • 1
    Possible duplicate of [how to get return response from AWS Lambda function](http://stackoverflow.com/questions/36784925/how-to-get-return-response-from-aws-lambda-function) – Gricey May 21 '17 at 00:23
  • @Gricey, the other question deals with asynchronous call (HTTP 202, "Event"). Here it's a synchronous call (HTTP 200, "RequestResponse"). So... Not a duplicate. At least not this one. – Grzegorz Oledzki Oct 07 '17 at 10:00
  • 1
    @GrzegorzOledzki the answer to the duplicate I link says that they should be using `RequestResponse`. However I've added an answer so that there's something here for the question as asked. – Gricey Oct 08 '17 at 05:33

1 Answers1

20

The response data you're looking for is there, it's just inside the Payload as a StreamingBody object.

According to the Boto docs, you can read the object using the read method:

invoke_response['Payload'].read()
Gricey
  • 1,321
  • 1
  • 18
  • 38