lambda-warmer icon indicating copy to clipboard operation
lambda-warmer copied to clipboard

Concurrency > 1, don´t work in lambda function in VPC

Open eduardoflorence opened this issue 5 years ago • 5 comments

When the concurrency parameter is greater than one, if the lambda function is not in a VPC, everything works normally, but if it is in a VPC the promise is never resolved. If I put concurrency equal to one, it works normally in VPC. Please, is there any way to resolve this?

eduardoflorence avatar Apr 17 '19 22:04 eduardoflorence

Hi Jeremy, I also have the same issue. When my lambda function is not in a VPC then the lambda-warmer works perfectly. However when it is in a VPC it always times out. I've tried putting my Lambda in both a public and private subnet with internet gateway/nat gateways with no success. I'm very new to AWS so any assistance you can give will be greatly appreciated.

craig-cubie avatar Apr 21 '19 04:04 craig-cubie

Thanks for the report. I am looking into this.

jeremydaly avatar Apr 22 '19 16:04 jeremydaly

This is most likely a issue with your VPC configuration, rather then this module. When lambda.invoke() is called from the aws-sdk library, it makes an HTTP request, using the syntax shown here: https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html

Try making any outgoing HTTP request with your lambda function. If it fails, then you will not be able to call Invoke.

The solution is to use two subnets, one public and one private. Create an Internet Gateway to connect the VPC to the internet. Create a NAT Gateway inside the public subnet. Create a route in the public subnet to the Internet Gateway, and a route in the private subnet to the NAT Gateway. More details can be found here: https://stackoverflow.com/a/39206646/1431777

I am currently using lambdas in a VPC, and can confirm that Concurrency > 1 works, given this architecture.

jmhummel avatar May 09 '19 01:05 jmhummel

I encountered this issue as well and it was because the VPC didn't have outbound access. What got me was that the NAT instance I had created was in a private subnet. Making a new one in a public subnet solved the issue.

scottcwilliams511 avatar Jul 25 '19 20:07 scottcwilliams511

Having same issue when lambda is inside VPC -- one workaround is adding multiple same targets to your lambda from Cloudwatch event rule and make concurrency always as 1.

Concurrency calls will be made at same time, you'll find trace data from X-Ray. And in my case, the lambda in VPC will be destroyed around 12 mins, not 15 mins.

XiamiYoung avatar Sep 13 '20 09:09 XiamiYoung

I'll be closing this issue, @jmhummel's answer seems to resolve this.

If anyone wants this to be re-opened, let me know. Also, if anyone wants to open a PR that explains this in the README it'll be very welcome 🙏

naorpeled avatar Jan 13 '23 20:01 naorpeled