PhantomJS on AWS Elastic Beanstalk

In order to run a headless browser on AWS EB, PhantomJS should be available on the box. However, 64bit Amazon Linux 2016.09 v2.3.3 does not have PhantomJS pre-installed, unlike NPM (/usr/bin/npm) or NodeJS (/usr/bin/node).

One methodology I came across thanks to Mark Baird's was to add AWS EB configuration file to the project and have it install as part of the deploy.

Create a file name install_phantomjs.config under .ebextensions with the following config:

commands:  
  01_download_phantomjs:
    command: wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
  02_create_phantomjs_directory:
    command: sudo mkdir -p /opt/phantomjs
  03_unbzip2_phantomjs:
    command: bzip2 -df phantomjs-2.1.1-linux-x86_64.tar.bz2
  04_untar_phantomjs:
    command: sudo tar -xvf phantomjs-2.1.1-linux-x86_64.tar --directory /opt/phantomjs/ --strip-components 1
  05_symlink_phantomjs:
    command: sudo ln -fs /opt/phantomjs/bin/phantomjs /usr/bin/phantomjs

Now, every time you deploy to AWS EB, PhantomJS will be automatically installed and accessible globally.

Happy headless browser!

Share this: