Skip to content

Instantly share code, notes, and snippets.

@FrederikLi
Last active November 6, 2023 12:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrederikLi/75c4e3a6a072540845313b215d55959b to your computer and use it in GitHub Desktop.
Save FrederikLi/75c4e3a6a072540845313b215d55959b to your computer and use it in GitHub Desktop.
AWS Lambda nodejs10.x serverless + phantomjs
Download phantomjs 2.1.1 for linux
https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
(https://bitbucket.org/ariya/phantomjs/downloads/)
Move exectuable to root folder: ./lib/phantomjs
Download phantom-lambda-fontconfig-pack
https://github.com/naeemshaikh27/phantom-lambda-fontconfig-pack
Create fonts folder, move *.ttf + *.conf there.
Move all lib*.so.[version] to the root directory
Change contents of fonts/font.conf to:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/var/task/fonts/</dir>
<cachedir>/tmp/fonts-cache/</cachedir>
<config></config>
</fontconfig>
Directory should look like that:
+ lib
+ phantomjs
+ fonts
+ fonts.conf
+ *.ttf
+ lib*.so.[version]
+ node_modules
+ package.json
+ serverless.yml
(https://github.com/marcbachmann/node-html-pdf/issues/547)
Update environment variable in code:
process.env['FONTCONFIG_PATH'] = path.join(process.env['LAMBDA_TASK_ROOT'], 'fonts');
Works on Node.js 10.x (Should for on Node.js 12.x as well)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment