简体   繁体   English

从另一个 Lambda 调用 AWS Lambda function 超时错误

[英]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.尝试从另一个 Lambda 调用 Lambda function 时出现超时错误。

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 su.net be assigned to each Lambda?使用这种方法,应该只给每个Lambda分配public su.net吗?

Both Lambdas can successfully run independently and can access the Inte.net.两个 Lambda 都可以独立运行成功,并且可以访问 Inte.net。

What else do I need to configure?我还需要配置什么?

Current configuration followed:当前配置如下:

Create 2 Su.nets, let one be denoted as private and the second public (these terms are explained ahead, keep reading).创建 2 个 Su.net,让一个表示为私人的,第二个表示为公共的(这些术语在前面解释,继续阅读)。 Create an Inte.net Gateway - this is a virtual router that connects a VPC to the inte.net.创建一个 Inte.net 网关 - 这是一个将 VPC 连接到 inte.net 的虚拟路由器。 Create a NAT Gateway - pick the public su.net and create a new elastic IP for it (this IP is local to your VPC) - this component will pipe communications to the inte.net-gateway.创建一个 NAT 网关 - 选择公共 su.net 并为其创建一个新的弹性 IP(这个 IP 在你的 VPC 本地) - 这个组件将 pipe 通信到 inte.net-gateway。 Create 2 Routing Tables - one named public and the second private.创建 2 个路由表 - 一个名为 public,第二个为 private。

In the public routing table, go to Routes and add a new route: Destination: 0.0.0.0/0在公共路由表中,go 到 Routes 并添加一条新路由:Destination: 0.0.0.0/0

Target: the ID of the inte.net-gateway目标:inte.net-gateway 的 ID

In the private routing table, go to Routes and add a new route: Destination: 0.0.0.0/0在私有路由表中,go到Routes,添加一条新路由:Destination:0.0.0.0/0

Target: the ID of the nat-gateway target:nat-gateway的ID

A private su.net is a su.net that in its routing table - there is no route to an inte.net-gateway.私有 su.net 是在其路由表中没有到 inte.net 网关的路由的 su.net。

A public su.net is a su.net that in its routing table - there exists a route to an inte.net-gateway公共 su.net 是在其路由表中的 su.net - 存在到 inte.net 网关的路由

Edit: The two Lambdas are in the same security group- is that correct?编辑:这两个 Lambda 在同一个安全组中——对吗? I have also tested that the Lambdas can successfully connect to a RDS database in the same VPC.我还测试了 Lambdas 可以成功连接到同一 VPC 中的 RDS 数据库。

This is the Python I am using to invoke the second Lambda:这是我用来调用第二个 Lambda 的 Python:

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)

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.可能会出现许多问题,这些问题会触发 SDK 重试调用,最终可能会导致超时。

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. VPC 配置是其中之一,但我遇到的另一个是当所讨论的 Lambda 没有足够的权限调用另一个时。

Be sure you have an IAM policy like the following in place for the Lambda that needs to invoke the other.确保您为需要调用另一个的 Lambda 准备了如下所示的 IAM 策略。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM