Boto3: Using invoke to call another lambda function always timeout.

Created on 10 Nov 2016  路  7Comments  路  Source: boto/boto3

Hello,

Apologies if this is not the right place to file this issues. But please let me try to explain my situation.

I have an API Gateway that can successfully call a lambda function. This lambda function base on a certain condition should invoke another lambda function. The code is very simple:

import boto3, json, logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)

client = boto3.client('lambda')

def lambda_handler(event, context):
    raw_event = event.get('body')
    if raw_event.get('event') == "voicecall_final":
        # trigger the next lambda function
        res = client.invoke(
            FunctionName='aggregate',
            InvocationType='RequestResponse',
            Payload=json.dumps({'engagement_id': raw_event.get('engagement_id')})
        )

However I can't seem to reach other function, the other function is just printing the payload for now. I cannot even get the res variable. Here are the logs:

START RequestId: 21583ec8-a737-11e6-8d5b-a76626b2b591 Version: $LATEST
[INFO]  2016-11-10T11:16:30.994Z    21583ec8-a737-11e6-8d5b-a76626b2b591    Starting new HTTPS connection (1): lambda.us-west-2.amazonaws.com
END RequestId: 21583ec8-a737-11e6-8d5b-a76626b2b591
REPORT RequestId: 21583ec8-a737-11e6-8d5b-a76626b2b591  Duration: 3002.54 ms    Billed Duration: 3000 ms    Memory Size: 128 MB Max Memory Used: 22 MB  
2016-11-10T11:16:33.977Z 21583ec8-a737-11e6-8d5b-a76626b2b591 Task timed out after 3.00 seconds

This is running under a VPC and I set the security group to accept all inbound and outbound connection. I use arn:aws:iam::aws:policy/AWSLambdaFullAccess manage role for both of them.

Am I missing something here?

closing-soon guidance

Most helpful comment

I am running Lambda as Kinesis consumer and invoking function in itself.

called_function = context.invoked_function_arn

lambda_client = boto3.client('lambda', region_name='my-region')
        lambda_client.invoke(
            FunctionName=called_function,
            InvocationType='Event',
            Payload=bytes(json.dumps(event_to_send))
        )

All 7 comments

I would advise against calling a lambda function from within a lambda function synchronously like that. It results in you effectively being double-billed.

In this case it looks like that other lambda function is taking so long that it's causing the initial function to time out. You will need to either increase your timeout, invoke the other lambda asynchronously, or optimize the other lambda function.

@JordonPhillips hmm, I'm only triggering the other lambda function if a certain condition is met, I'm not sure if that means double billed.

On the other hand, we are trying to print on the second function, I'm not sure what can I still optimized there. Indeed, I should call the other function asynchronously.

However, this seems to be some user permission issue that I can't debug, I tried to do it in my personal root account and everything seems perfectly fine.

Thanks for responding though. Closing this now.

I am having similar issue, I am unable to invoke lambda function asynchronously. Is there something I am missing.

@jgardezi as it turns out, my problem was I was running it on a public subnet, and lambda doesn't have an elastic ip to use internet gateway. So switching to private subnet with a nat solves my problem. I hope that helps you or have more clue about your problem.

I am running Lambda as Kinesis consumer and invoking function in itself.

called_function = context.invoked_function_arn

lambda_client = boto3.client('lambda', region_name='my-region')
        lambda_client.invoke(
            FunctionName=called_function,
            InvocationType='Event',
            Payload=bytes(json.dumps(event_to_send))
        )

By the way, API Gateway's main lambda will only run for 20s, that's why delegating synchronously to other lambdas is a bad idea

By the way, API Gateway's main lambda will only run for 20s, that's why delegating synchronously to other lambdas is a bad idea

This is untrue. Although the maximum timeout on the API Gateway is 29 seconds, the invoked lambda can run up to 300 seconds if its timeout is set to maximum. The invocation with return a timeout to the API caller, but the lambda will keep running.

Was this page helpful?
0 / 5 - 0 ratings