最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - A Lambda function that invoke another lambda function failed on cloud but working locally - Stack Overflow

programmeradmin4浏览0评论

I have 2 Lambda functions, function A will invoke function B with the following code:

response_lambda = lambda_client.invoke(
                        yieldFunctionName='arn:aws:lambda:ap-southeast-2:XXXXXXXXXXX:function:functionB',
                        InvocationType='Event',  # Change to 'Event' if async
                        Payload=payload_bytes
                    )

When I invoke Function A locally with sam, it runs successfully without any issue and Function B is invoked succesfully too. The command i used is:

sam local invoke functionA > response.json

However, when i deployed Function A to the cloud and run it to the cloud, it always gets timeout, I have tried:

  1. using an aws cli command to run in my local terminal, which is:

aws lambda invoke --function-name functionA --cli-binary-format raw-in-base64-out response.json

In response.txt, i get:

{"errorMessage":"2025-03-31T23:12:09.503Z aa35bxxx-734x-4b3x-94cb-xxxxxxxxxxx Task timed out after 20.02 seconds"}

In the console, i will read:

Read timeout on endpoint URL: ";

  1. Directly invoke in AWS Console of lambda functionA
  2. Invoking Function A with eventBridge scheduler

All of them got time out. I have set the Timeout of Function A in template.yaml to very long, say 1000 seconds, but it will time out anyways when the time comes.

I am suspecting in the cloud environment, the VPC of Function A cannot reach the internet to invoke Function B. Function A and B are sitting in the same VPC and i don't understand why AWS doesn't invoking each other internally.

Any clues on the solution is much appreciated! Thank you!

I have 2 Lambda functions, function A will invoke function B with the following code:

response_lambda = lambda_client.invoke(
                        yieldFunctionName='arn:aws:lambda:ap-southeast-2:XXXXXXXXXXX:function:functionB',
                        InvocationType='Event',  # Change to 'Event' if async
                        Payload=payload_bytes
                    )

When I invoke Function A locally with sam, it runs successfully without any issue and Function B is invoked succesfully too. The command i used is:

sam local invoke functionA > response.json

However, when i deployed Function A to the cloud and run it to the cloud, it always gets timeout, I have tried:

  1. using an aws cli command to run in my local terminal, which is:

aws lambda invoke --function-name functionA --cli-binary-format raw-in-base64-out response.json

In response.txt, i get:

{"errorMessage":"2025-03-31T23:12:09.503Z aa35bxxx-734x-4b3x-94cb-xxxxxxxxxxx Task timed out after 20.02 seconds"}

In the console, i will read:

Read timeout on endpoint URL: "https://lambda.ap-southeast-2.amazonaws/2015-03-31/functions/functionA/invocations"

  1. Directly invoke in AWS Console of lambda functionA
  2. Invoking Function A with eventBridge scheduler

All of them got time out. I have set the Timeout of Function A in template.yaml to very long, say 1000 seconds, but it will time out anyways when the time comes.

I am suspecting in the cloud environment, the VPC of Function A cannot reach the internet to invoke Function B. Function A and B are sitting in the same VPC and i don't understand why AWS doesn't invoking each other internally.

Any clues on the solution is much appreciated! Thank you!

Share Improve this question asked Mar 31 at 23:29 Bill KaryBill Kary 7052 gold badges12 silver badges27 bronze badges 1
  • If your VPC doesn't have NAT Gateway and you don't want to add it, then add a VPC Endpoint so that invocation requests from function A can reach the Lambda service endpoint. – jarmod Commented Apr 1 at 13:00
Add a comment  | 

1 Answer 1

Reset to default 2

Check the Subnets assigned to each AWS Lambda function.

If a Lambda function is connected to a VPC, then only private subnets should be assigned to Lambda functions. They can then use a NAT Gateway (in a public subnet) to access the Internet.

I suspect that your Function A is incorrectly connected to public subnets or has a security group that does not permit Outbound access.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论