would love to hear some opinions regarding hosting of an Angular Universal app.
Question – EC2 vs AWS Lambda
After finishing my application I initially created t2.micro linux instance to host my app, was happy to see that the site scores 97 in Googles page speed insight test.
Afterwards I came across AWS lambda, a serverless way to run my server rendering app!, as its cost depends on the amount of requests (which Is extremely low on my website) thought that could be a nice way to avoid paying $10 a month.
The only issue is – Google speed test (using AWS Lambda) scored a sad 80… with a huge red flag on server response time.
After doing a few more tests seems like the function became warmer and got up to 92. that’s not 98 but I can live with that.
The thing is, as Im planning to get about 20-50 requests spread through out the entire day it will stay cold, so SEO wise I’ll stay on 80 score website instead of 98.
Is there something I’m missing? As convenient as it is should I just stick with EC2 for my needs?
Thanks for reading <3
2
Answers
20-50 requests a day is definitely not much, so indeed your Lambda functions will run cold at some point (usually they go cold after 5 mins).
One option here is to create a CloudWatch event that runs every 4 mins and triggers your Lambda function.
Keep in mind that this would only spin up one single container. If you expect peaks, let’s say that 10 out of the 50 requests are concurrent, then you’d need to have your Lambda spin up another instance of the same function 10 times, so you wouldn’t have to worry about cold starts too much. However, since this can get messy quickly, I suggest your CloudWatch Event invokes a Lambda whose only responsibility is to warm up the real Lambda (i.e, calling the real Lambda 10 times concurrently) you’re going to use.
I suggest you read this article by AWS Community Hero Yan Cui, where he covers, in details, how Lambda cold starts work and how to avoid them.