Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call AWS lambda function from an existing lambda function on Python 2.7

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} 
like image 440
shiv455 Avatar asked Jul 17 '16 15:07

shiv455


People also ask

How do you call a lambda function from another lambda function in Python?

Let the name of this function be – “ChildFunction” and select Python 3.8 as the runtime. Select the option to Create a new role with basic lambda permissions and click on Create Function. A new lambda function will be created where you can write your code and test it.

Does Python 2.7 support lambda functions?

From the deprecation date of July 15, 2021, Lambda will no longer apply security patches and other updates to the Python 2.7 runtime used by Lambda functions. In addition, functions using Python 2.7 will no longer be eligible for technical support.


1 Answers

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() 
like image 186
Gricey Avatar answered Sep 29 '22 21:09

Gricey