Serverless with AWS Lambda

Lambdas Calling Lambdas Q&A

Scott Moss

Scott Moss

Superfilter AI
Serverless with AWS Lambda

Check out a free preview of the full Serverless with AWS Lambda course

The "Lambdas Calling Lambdas Q&A" Lesson is part of the full, Serverless with AWS Lambda course featured in this preview video. Here's what you'd learn in this lesson:

Scott takes questions from students about the tradeoffs and implementations of invoking other lambdas inside lambda functions.


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.

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.

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.

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.

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.

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.

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.

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.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now