tungs / timesnap

Node.js program that takes screenshots at smooth intervals of web pages with JavaScript animations
BSD 3-Clause "New" or "Revised" License
234 stars 57 forks source link

[FEATURE REQUEST] AWS Lambda Function #55

Open ariel-frischer opened 3 years ago

ariel-frischer commented 3 years ago

Great library I'm just wondering if anyone has managed to deploy this as an AWS lambda function (with or without a lambda layer). It seems the puppeteer module is quite large which makes things a bit more difficult. If you can share a bit of insight on how to accomplish this I would be grateful.

tungs commented 3 years ago

Though I don't have a lot of experience with this, some people, like andreastepel, have been trying this out with timecut— see tungs/timecut#44.

Long story short, there's a new version of timesnap that doesn't bundle the puppeteer dependency called timesnap-core. You can combine this with a smaller puppeteer package meant for AWS Lambda like chrome-aws-lambda.

The code would look something like this:

const timesnap = require('timesnap-core');
const chromium = require('chrome-aws-lambda');

exports.handler = async (event, context, callback) => {
  await timesnap({
    browser: chromium.puppeteer.launch({
      args: chromium.args,
      //... the rest of the arguments found in https://github.com/alixaxel/chrome-aws-lambda/blob/master/README.md
    }),
    url: event.url,
    outputDirectory: '/tmp'
    // ...
  });
  //
};