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

The "Sync vs. Async" 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 discusses executing lambdas synchronously and asynchronously.

Preview
Close

Transcript from the "Sync vs. Async" Lesson

[00:00:03]
>> Scott Moss: So, now we're gonna talk about and this is a brief topic. But I just wanna talk about basically two different ways of how you can execute a lambda. There is synchronous and then there is asynchronous. Who here thinks they know what I'm talking about when I say that?

[00:00:21]
Cuz it's tricky, I know you're thinking, it's JavaScript, yeah asynchronous, synchronous, that's what you're talking about. I'm not, I'm talking about something else. Anybody wanna take a stab at it? The two different modes of running a lambda function, synchronous or asynchronous. No, okay. Basically, synchronous mode is when you call a lambda and you're waiting for the response to come back.

[00:00:44]
So this is like an API event. This is like I'm on a server and I'm calling a lambda. This is a client calling a lambda that's waiting on a response. It's what your servers do now. When you make a call to an API you wait for the response to come back.

[00:00:57]
It's happening in async but it's synchronous cuz you're waiting for it to come back, it's blocking. Asynchronous lambda is something that you fire and you forget about it. It's not gonna respond back to you. It's gonna go update S3 somewhere or send an email in the background or update a DynamoDB table for some reason.

[00:01:15]
That's an asynchronous lambda. So those are two different context in which you can call lambdas. And that's very important because depending on what context you're running in can affect your performance. It can affect a lot of things so you got to be careful how you actually execute those lambdas.

[00:01:33]
And that only comes down to when you actually call the lambda yourself using the AWSSDK. So if you use the SDK and you invoke a lamda using the SDK, whether it's on your node server or inside of another lambda, maybe on the client, I don't why you're doing it but you can do it.

[00:01:50]
You'll have the option to say, I want this to be synchronous or not synchronous. And then you can do that there. There are some trade-offs

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