Inspecting Vapor on AWS0:00
Okay, we have our application deployed to AWS through Laravel Vapor. We verified that the HTTP component works as well as the Scheduler, Queue and artisan components. Now, let's explore what Vapor did to make the application run serverlessly. We will go to our AWS console and go to the Lambda dashboard. Let's close this side menu and we can see that we have three Lambda functions in our AWS account. One for the Queue, one for the HTTP handler and one for CLI commands. Let's check the HTTP Lambda. If we scroll down a little, we can see there is an aliases tab. Let's click on this one. Vapor seems to have created an alias called Production that points to a specific version of this Lambda.
Understanding Lambda Cold Starts3:13
The first attribute indicates that this invocation is coming from something called Vapor Warmer. The second attribute indicates some sort of concurrency. So, what's all this? The way Lambda works under the hood is that it starts a number of containers for each function to handle incoming triggers. By default, we cannot control how many containers AWS will start for us, or how long these containers will live before they get terminated and new ones start. When a new container is booted up, the time it takes for it to be ready to handle triggers can reach up to a few seconds. This event of booting up new containers is called a cold start. For CLI commands and queue drops, that's not a big deal. But for HTTP requests, that's not acceptable.
Warming with EventBridge4:01
For CLI commands and queue drops, that's not a big deal. But for HTTP requests, that's not acceptable. We want to control the number of containers alive and warm and ready to handle HTTP requests as soon as they come. And for that reason, Vapor uses EventBridge to trigger a Lambda function. This function's only task is to send concurrent requests to a number of containers to cold start them before any actual requests come to the application. This will ensure a number of containers is always warm, always there to handle requests. Now, let's go back to the functions list. Click on the CLI function, go to aliases, production, and check the triggers. We can see that the CLI function has a single trigger, which is an EventBridge event.
