Include custom fonts in AWS Lambda

后端 未结 5 1752
独厮守ぢ
独厮守ぢ 2021-01-25 17:16

Does Anyone know something like ebextensions[2] in EC2 for AWS Lambda?

The goal is to install custom fonts in the AWS Lambda execution environment.

5条回答
  •  一向
    一向 (楼主)
    2021-01-25 17:51

    A lot of the answer on this subject of using fonts on Lambda's were a bit incomplete.

    My scenario required using a custom font in conjunction with Imagemagick. I checked out out this branch with Imagemagick and Freetype support and worked through the README. The key for my use case is the lambda or lambda layer used in the function needed freetype support to access my fonts. I'm using a TTF.

    After deploying the lambda layer, in my Lambda function's directory I did the following:

    • At the root of my lambda create a fonts directory.
      • In the fonts directory add the TTF or your font.
        • I'm using serverless framework so this directory once deployed will be located at /var/task/fonts.
      • Also in the fonts directory include the following fonts.conf.
    
    
    
      /var/task/fonts/
      /tmp/fonts-cache/
      
    
    
    • Finally, in your serverless.yml add the following directory so that your fonts and fonts.conf will be included in the lambda.
    package:
        include:
            - fonts/**
    

    Because freetype is now accessible in the lambda layer any fonts in the fonts directory will be accessible. Could have also dynamically downloaded fonts needed, but I decided to choose include in my lambda function.

提交回复
热议问题