Transcript from the "Lambdas Calling Lambdas Q&A" Lesson
>> Scott Moss: Yes.
>> Student: So seems likely that from here, I might trigger events to trigger other landers, can I do that?
>> Scott Moss: You bet, yeah.
>> Student: I'm like can I do that?
>> Scott Moss: Yeah, can you.
>> Student: [LAUGH]
>> Scott Moss: Yeah, it sounds really cool and you know what, there you can do it.
[00:00:16] It's the problem is like, how to do it effectively and efficiently because you can go on, so I'm gonna get into a little bit of how lambdas actually work and the architecture underneath them. The way they work is AWS spins up a container, right and that container gets recycled.
[00:00:33] But inside that container, that's when your lambda actually gets executed. So what happens is let's say you haven't executed a lambda in like a day. You finally execute a lambda, that creates a container and then that spins up your line of functions, so there's a cold start there, that's gonna take some time, it's not warm yet.
[00:00:49] So, that's gonna take some overheat and then your lambda executes. And if you heat it like within, whatever, you know frequency that ADS decides to recycle things, nobody really knows the exact number, it's between 5 and 20 minutes. I've been looking, nobody knows the number, then, it's warm, you're good.
[00:01:06] So if you have a lambda that you hit with a HTTP request that was cold, there's a cold start there. And then, let's say you've got some database connections there, this has got to connect to those databases. And then, inside that lambda, you hit another lambda that had a cold start there.
[00:01:18] And then, it had database connections, you could imagine, it could be really, really slow. And eventually it's compounded, so, it sounds cool at first but it really all depends on like what you're doing in those lambdas. If they are async versus synchronous, like if I'm calling a lambda and just forgetting about it cuz it's doing something in the background, that's fine.
[00:01:35] It's never gonna hurt you, but if you're calling a lambda that's calling another lambda and it's waiting on that lambda and you're client's waiting on the first lambda. Your API's gonna be pretty slow and not to mention right now, API Gateway adds somewhere between 200 milliseconds of delay to every single request and they're working on that, but that's a lot.
[00:01:53] Just 200 milliseconds right off the bat for using API Gateway. So there's a lot of trade offs there, so you can totally do it but, probably shouldn't, at least not without figuring out what you're doing.