4

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

Ben
  • 793
  • 2
  • 13
  • 29

2 Answers2

1

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.

Thales Minussi
  • 6,965
  • 1
  • 30
  • 48
  • Well.. having a CloudWatch Event that triggers the lambda 10 times every 5 minutes means I'll pass the 1M free requests limitation... if thats the case seems like Im better off simply running it on a server and pay $10 a month and rest assure for maximum performance all the time? ... ty! – Ben Mar 25 '19 at 16:23
  • @Ben If you still look at the pricing of lambda its still very less https://aws.amazon.com/lambda/pricing/ – amittn Mar 25 '19 at 16:27
  • @amittn good point haha, I'll configure the lambda warmer and check in a few hours to see how it results when I request a google speed test. ty – Ben Mar 25 '19 at 16:49
  • @Ben even if you ran it 10 times every 5 mins you'd not cross the 1M free requests: 5 * 10 * 12 * 24 * 30 = 432K a month. 43% of your monthly quota. But that's considering you may get 10 concurrent requests, which I don't think is the case. Warming it up every 5 mins should do the job. – Thales Minussi Mar 25 '19 at 16:59
  • Explanation of my formula: 5 = minutes / 10 = concurrent requests / 12 = invocations per hour / 24 = hours per day / 30 = days per month – Thales Minussi Mar 25 '19 at 17:00
  • 1
    True, miscalculated that. Giving a shot with the warmer now crossing my fingers that will keep the score at 90+ at all times. Ty – Ben Mar 25 '19 at 17:04
  • I saw on your comments that it is just a static app. Have you considered s3 static hosting? – Thales Minussi Mar 25 '19 at 17:30
  • Oh its not a real static app, its Server Side Rendering. so s3 static hosting won't work here. ty :) – Ben Mar 25 '19 at 18:06
  • @Ben How did you got to acchieve 80-90 score with Angular SSR on Lambda? I barely hit 70, and not sure what is it (https://homezone.al) – albanx May 30 '23 at 23:05
1
  • If its just Google speed test that pulling you back from using aws lambda (I would suggest to use synthetic transaction also known as active monitoring or proactive monitoring or using CloudWatch Events “ping”) which would help you keep the lambdas worm.
  • As long as you are in the monthly 1 million free invocations it wont cost you a pennies.
  • It also depends up the traffic you are seeing/expecting on your site, because it will be the guiding force to select the method, how you want to implement the keep warm bit(synthatic transaction or cloudwatch event ping).
  • hope this link helps its just talking about cloud watch ping method but its covering single concurrency and multiple concurrency methods https://www.jeremydaly.com/lambda-warmer-optimize-aws-lambda-function-cold-starts/
  • And synthetic transaction is nothing but doing a whole user journey on your site like once every 10 minutes but its more of monitoring then keep the lambda warm.
amittn
  • 2,249
  • 1
  • 12
  • 19
  • To answer your question "If its just Google speed test that pulling you back" Yes!, it is only google speed test. and yet seems like the solution isnt worth it. as I may pass the free limitation and risk not having 100% performance at all time? do you still believe I should use it for my needs or simply run it on a linux instance? – Ben Mar 25 '19 at 16:23
  • @Ben It all depend what you are aiming for and what your app is doing 1) If its a bronze service and you don't care if the app is a bit slow because of the the latency issues (I would give it a try for a month at lest) 2)If you are planning to run the app for next couple of years then i would think of going for reserved instance and reduce the cost accordingly and then compare the long term benefits. – amittn Mar 25 '19 at 16:53
  • I dont care as much for the user experience... as even when its cold it ain't that bad as its basically just a static website at the end. My issue is that Iv'e been told that the SEO will be a lot better having 97 score in google speed test compared to 75-85 – Ben Mar 25 '19 at 17:04