简体   繁体   中英

AWS Lambda in VPC interacting with Database

I recently asked a question to a professor in a QA session. I didn't have the chance to follow up the question because of the volume of the questions asked that day.

So the question is: How do people (in general) get around of the cold start time of AWS Lambda in VPC interacting with RDS?

And his answer is: The ENI which is the long part of the process only attaches at the beginning of the container. So if you run a small select top 1 on your database each minute or so it will keep the connection open and not have to attach the ENI

So my follow up question is,

I have multiple lambda functions. Should I run the SELECT TOP 1 on a single lambda function, or should I ping all of my lambda functions from cloudwatch (and select TOP 1) if the event is from cloudwatch?

Thank you!

The issue is not with the RDS, but with the Lambda provisioning. The whole ENI thing happens when you've got a "cold" lambda job (one which is not running and not assigned to any container instance). When you try to run a "cold" Lambda job you'll end up experiencing rather large latency no matter what: the AWS system must find a vacant instance, copy your job there, provision additional resources (ENIs, routing table entries, etc.) and only then execute your code (and the execution latency itself may also be rather high if you're using Java or C#).

To prevent your job from going "cold" you don't have to ping the database. You just have to ensure that the job is invoked regularly and often enough, even if it does nothing (you can add a field to your job parameter or environment to the tune "do nothing and exit").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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