offtheradar
offtheradar

Reputation: 35

Timeout error invoking AWS Lambda function from another Lambda

I'm getting a timeout error when trying to invoke a Lambda function from another Lambda.

I have followed the steps below that I found in another post but still can't get it working. Using this method, should only the public subnet be assigned to each Lambda?

Both Lambdas can successfully run independently and can access the Internet.

What else do I need to configure?

Current configuration followed:

Create 2 Subnets, let one be denoted as private and the second public (these terms are explained ahead, keep reading). Create an Internet Gateway - this is a virtual router that connects a VPC to the internet. Create a NAT Gateway - pick the public subnet and create a new elastic IP for it (this IP is local to your VPC) - this component will pipe communications to the internet-gateway. Create 2 Routing Tables - one named public and the second private.

In the public routing table, go to Routes and add a new route: Destination: 0.0.0.0/0

Target: the ID of the internet-gateway

In the private routing table, go to Routes and add a new route: Destination: 0.0.0.0/0

Target: the ID of the nat-gateway

A private subnet is a subnet that in its routing table - there is no route to an internet-gateway.

A public subnet is a subnet that in its routing table - there exists a route to an internet-gateway

Edit: The two Lambdas are in the same security group- is that correct? I have also tested that the Lambdas can successfully connect to a RDS database in the same VPC.

This is the Python I am using to invoke the second Lambda:

try:
    invoke_response = lambda_client.invoke( 
        FunctionName='test_function',
        InvocationType='Event',
        LogType='None',
        Payload=json.dumps(test_payload),
    )
except Exception as invoke_error:
    print(invoke_error)

Upvotes: 0

Views: 2028

Answers (1)

Nino van der Mark
Nino van der Mark

Reputation: 721

There are a number of issues that can arise which will trigger the SDK to retry the invocation, and that may eventually result in a timeout.

VPC configuration is one of these, but another that I ran into was when the Lambda in question has insufficients rights to invoke the other.

Be sure you have an IAM policy like the following in place for the Lambda that needs to invoke the other.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "LambdaInvoke",
            "Action": "lambda:InvokeFunction",
            "Effect": "Allow",
            "Resource": "<arn of other Lambda>"
        }
    ]
}

Upvotes: 1

Related Questions