DEV Community

Cover image for A developers guide to Run Puppeteer on Elastic Beanstalk (no ubuntu linux)
Achilles Moraites
Achilles Moraites

Posted on

A developers guide to Run Puppeteer on Elastic Beanstalk (no ubuntu linux)

The problem with running puppeteer on elastic beanstalk is that chrome is not included by default.

This has been published on Medium

Make sure you have

Install chrome on elastic beanstalk

Connect with ssh to elastic beanstalk
To connect with ssh the easiest way is to use:

eb ssh
Enter fullscreen mode Exit fullscreen mode

after you have connected, run the following command

curl https://intoli.com/install-google-chrome.sh | bash
Enter fullscreen mode Exit fullscreen mode

the command above fetches and runs the installation script on elastic beanstalk.

Lets Use it

After we have chrome installed we need to setup puppeteer to use it instead of the default chromium that will not work no matter what.

here you can see a simple snippet of how we can use puppeteer to take a screenshot of a page in www.example.com , note the executablePath is pointing to the directory where our installed chrome lives.

'use strict';                                               
const puppeteer = require('puppeteer');

(async() => {

const browser = await puppeteer.launch({executablePath: '/usr/bin/google-chrome-stable',
headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox']});

const page = await browser.newPage();

await page.goto('https://www.example.com');                                                               

await page.screenshot({ path: 'screenshot.png', fullPage: true });

browser.close();

})();
Enter fullscreen mode Exit fullscreen mode

Congrats you can now use Puppeteer on elastic beanstalk !

cover photo by Magda Ethels

Top comments (4)

Collapse
 
boutell profile image
Tom Boutell

I know this is an older post, and I appreciate the advice, but I am not sure this really works when you scale beyond the smallest tier with Elastic Beanstalk.

As the docs say, "If an environment has multiple running instances, EB CLI prompts you to specify which instance you want to connect to." You would have to install it on every instance, it would not be installed on new instances, it would not be installed if autoscaling was in use, etc.

And:

"Elastic Beanstalk applications run on Amazon EC2 instances that have no persistent local storage. When the Amazon EC2 instances terminate, the local file system isn't saved. New Amazon EC2 instances start with a default file system."

So I don't think this is a good long-term solution as written.

However it looks like at least the default install of chromium that comes with the npm puppeteer package should work fine on EB because EB always runs npm install for you when deploying node applications. If that doesn't work for you and you must have Chrome, then I think you'll need a different solution to ensure this really runs on every instance every time, like using the "sources" key as described in the EB docs.

Collapse
 
cdbrouk profile image
brouk

Amazing!
Perfect Answer!

Thanks!!!!!!!!!!!!!!!!!!!!😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀

Collapse
 
giovanigenerali profile image
Giovani Generali

It worked perfectly, thanks!

Collapse
 
tomgreeen profile image
tomgreeEn

Thanks for this guide - very clear. I have one question though - how can I find the executablePath where chromium was installed on elastic beanstalk ?