Coder Social home page Coder Social logo

xavsio4 / lambda-browser-screenshots Goto Github PK

View Code? Open in Web Editor NEW

This project forked from beneboy/lambda-browser-screenshots

0.0 0.0 0.0 28 KB

Take screenshots of web pages using AWS Lambda ๐Ÿ“ธ. Ready to deploy, no configuration needed.

License: Apache License 2.0

JavaScript 84.72% Makefile 15.28%

lambda-browser-screenshots's Introduction

Lambda Browser Screenshots

AWS Lambda function that gives a REST API that returns a PNG screenshot of a given URL. Small and easy to deploy without having to worry about S3.

What?

A batteries-included single file NodeJS application that takes a URL query string and returns a screenshot of that page in PNG format. Useful to integrate as a microservice with other applications. Uses Chromium/Puppeteer to render the pages. This should "just work" without having to figure out the right versions and host Chromium in an S3 bucket and so on.

How?

Build using make:

$ make

Or if you don't have make, run the build steps manually:

$ cd src
$ npm install --production
$ zip -r ../function.zip .

Either way, you should get an output file function.zip.

Now upload the function.zip to your Lambda in AWS.

AWS Setup

Supports Node 14.x Lambda runtime.

You should set up a REST API as the trigger to the function. Make sure that you add image/png as a Binary media type in the REST API configuration, otherwise you'll get back base-64 encoded data.

When making the request, you must specify the HTTP header Accept: image/png otherwise, again, you'll get back base-64 encoded data.

The screenshotter runs faster when you can allocate more RAM to your Lambda function, ~1600MB seems to be good to get a screenshot back within 2-3 seconds. Depending on your region and so forth you should be able to get 1,000,000 executions for ~$60USD.

Usage

The parameters that can be specified are:

  • url (required): The URL to screenshot
  • width (optional): The width of the browser window, defaults to 1280
  • height (optional): The height of the browser window, defaults to 800

Example Using Curl

$ curl -H "Accept: image/png" \
  https://FUNCTION_ID.execute-api.REGION.amazonaws.com/default/browser-shot\?url\=https://www.example.com\&width\=800\&height\=600 \
  > example.com.png

Why?

There's a ton of example code out there for doing this, but it can be dependency hell to get it working. Different versions of Puppeteer and Chromium have bugs to deal with and don't work right.

This is a ready-to-go solution that you can build and upload to AWS Lambda without having to waste time trying to sort out dependencies. When packaged it's less than 50MB including the node_modules you can easily upload to Lambda without having to go via S3.

lambda-browser-screenshots's People

Contributors

beneboy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.