Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using invoke to call another lambda function always timeout. #885

Closed
zkanda opened this issue Nov 10, 2016 · 7 comments
Closed

Using invoke to call another lambda function always timeout. #885

zkanda opened this issue Nov 10, 2016 · 7 comments
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.

Comments

@zkanda
Copy link

zkanda commented Nov 10, 2016

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?

@zkanda zkanda changed the title Using invoke to call another lambda function. Using invoke to call another lambda function always timeout. Nov 10, 2016
@JordonPhillips
Copy link
Contributor

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 JordonPhillips added guidance Question that needs advice or information. closing-soon This issue will automatically close in 4 days unless further comments are made. labels Nov 11, 2016
@zkanda
Copy link
Author

zkanda commented Nov 14, 2016

@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.

@zkanda zkanda closed this as completed Nov 14, 2016
@jgardezi
Copy link

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

@zkanda
Copy link
Author

zkanda commented Jun 13, 2017

@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.

@jgardezi
Copy link

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

@mojimi
Copy link

mojimi commented Mar 31, 2019

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

@RKamoi
Copy link

RKamoi commented May 24, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

5 participants