How can I execute a puppeteer script in the cloud as a single task?

Viewed 11

I am trying to create an analytics tool similar to https://pagespeed.web.dev where you insert a URL and it measures the performance of the website. Moreover, the tool would run a type of lighthouse audit called user-flow and collect data related to specific interactions such as scroll and clicks.

I would love to deploy it on lambda but there are way too many issues and well I have now figured out that will not work, or think so at least. The reason for that is that it needs to run on a stronger machine or it will fail to extract data in particular the performance measurement and leave it as "?" a question mark.

Lambda isn't a supported environment. Some of Lighthouse might work and some community packages attempt to make it more stable, but we can't commit to ensuring everything works as expected, see Run on Adequate Hardware docs.

They suggest running it on AWS's m5.large instance, however, I do not want to have an instance running just for that, and it's quite expensive.

So I need to find a way to do something similar to lambda with that instance but I don't get how the scheduling would work.

Some sudo code of what I would like is:

OnClick -> 
  Call Api (Api Gateway GET) > 
    Trigger Lambda (validates data) > 
      Send to Task Queue

And the task queue would need to function something like this:

 - If last item in queue <>
   - If instance is not running <> 
     Activate instance >
   Run Performance Test >
   Store Performance Test in S3
   Tell browser results are ready
   - If no its the only item in the queue <>
     Stop instance
   Remove itself from Queue

I have not used SQS or SNS before so I don't really understand what can be done or how that would be done. (But from my research that seems to be the direction)

How can I achieve this?

Is there a service that may help me coordinate this?

Is there a tutorial or case study that I can read?

Any suggestions, recommendation or input is welcome.

0 Answers
Related