Backward

Run Puppeteer/Chrome Headless on EC2 Amazon Linux



If you're using EC2 which run Amazon Linux, and you'd like to try Google's Puppeteer (Chrome Headless), below's tutorial verified on a  EC2 instance run the latest Amazon Linux AMI release 2017.09.

1. Install Puppeteer 0.12
# Install Node from npm
$ curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
$ sudo yum install -y nodejs gcc-c++ make
# Install puppeteer
$ mkdir my_project
$ cd my_project
$ npm i puppeteer
$ cd node_modules/puppeteer/
# Chrome version may be different depending on the version of Puppeteer.
$ cd .local-chromium/linux-508693/chrome-linux
$ ldd chrome | grep not

2. Install Chrome dependencies

After run ldd, you should get below output:
$ ldd chrome | grep not
	libpangocairo-1.0.so.0 => not found
	libpango-1.0.so.0 => not found
	libcairo.so.2 => not found
	libXcursor.so.1 => not found
	libXdamage.so.1 => not found
	libXfixes.so.3 => not found
	libcups.so.2 => not found
	libXss.so.1 => not found
	libXrandr.so.2 => not found
	libgconf-2.so.4 => not found
	libatk-1.0.so.0 => not found
	libgtk-3.so.0 => not found
	libgdk-3.so.0 => not found
	libgdk_pixbuf-2.0.so.0 => not found

Most of them can be resolved with a simple yum install:
$ sudo yum install cups-libs dbus-glib libXrandr libXcursor libXinerama cairo cairo-gobject pango

Let's run ldd again:
$ ldd chrome | grep not
	libXss.so.1 => not found
	libgconf-2.so.4 => not found
	libatk-1.0.so.0 => not found
	libgtk-3.so.0 => not found
	libgdk-3.so.0 => not found
	libgdk_pixbuf-2.0.so.0 => not found

Now only 6 left, as Amazon Linux don't have gtk builtin, we need borrow packages from other distributions:

# Install ATK from CentOS 7
$ sudo rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/atk-2.22.0-3.el7.x86_64.rpm
$ sudo rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/at-spi2-atk-2.22.0-2.el7.x86_64.rpm
$ sudo rpm -ivh --nodeps http://mirror.centos.org/centos/7/os/x86_64/Packages/at-spi2-core-2.22.0-1.el7.x86_64.rpm

# Install GTK from fedora 20
$ sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/g/GConf2-3.2.6-7.fc20.x86_64.rpm
$ sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libXScrnSaver-1.2.2-6.fc20.x86_64.rpm
$ sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libxkbcommon-0.3.1-1.fc20.x86_64.rpm
$ sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libwayland-client-1.2.0-3.fc20.x86_64.rpm
$ sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/l/libwayland-cursor-1.2.0-3.fc20.x86_64.rpm
$ sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/20/Fedora/x86_64/os/Packages/g/gtk3-3.10.4-1.fc20.x86_64.rpm

# Install Gdk-Pixbuf from fedora 16
$ sudo rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/16/Fedora/x86_64/os/Packages/gdk-pixbuf2-2.24.0-1.fc16.x86_64.rpm

Final check:
$ ldd chrome | grep not
# Great, all dependencies are resolved.

Time to take snapshot:
$ ./chrome --headless --disable-gpu --screenshot https://www.chromestatus.com/

And here's what we got:

Recommended for you
Comments 0