AWS Lambda 添加字体依赖项

将字体文件放在名称为 fonts 的文件夹中
压缩打包成 .zip 文件。

  • 然后通过Layer 的方式部署到 Lambda 中。
    在 Lambda 函数运行时,字体文件将会被解压缩释放到 /opt/fonts 目录下。

  • 且为函数添加环境变量:FONTCONFIG_PATH=/opt/fonts


The Amazon Linux 2 AWS Lambda runtime is no longer provisioned with any font faces.

Because of this, this package ships with Open Sans, which supports the following scripts:

  • Latin
  • Greek
  • Cyrillic

To provision additional fonts, simply call the font() method with an absolute path or URL:

await chromium.font('/var/task/fonts/NotoColorEmoji.ttf');
// or
await chromium.font('https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf');

Noto Color Emoji (or similar) is needed if you want to render emojis.

For URLs, it’s recommended that you use a CDN, like raw.githack.com or gitcdn.xyz.

This method should be invoked before launching Chromium.

On non-serverless environments, the font() method is a no-op to avoid polluting the user space.


Alternatively, it’s also possible to provision fonts via AWS Lambda Layers.

Simply create a directory named .fonts and place any font faces you want there:

.fonts
├── NotoColorEmoji.ttf
└── Roboto.ttf

Afterwards, you just need to ZIP the directory and upload it as a AWS Lambda Layer:

zip -9 --filesync --move --recurse-paths .fonts.zip .fonts/

参考: