jeremydaly / lambda-warmer

A module to optimize AWS Lambda function cold starts
MIT License
525 stars 55 forks source link

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

Closed eduardoflorence closed 1 year ago

eduardoflorence commented 5 years ago

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?

craig-cubie commented 5 years ago

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.

jeremydaly commented 5 years ago

Thanks for the report. I am looking into this.

jmhummel commented 5 years ago

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.

scottcwilliams511 commented 5 years ago

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.

XiamiYoung commented 4 years ago

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.

naorpeled commented 1 year ago

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 🙏