├── .gitignore ├── fonts ├── stix_fonts │ ├── fonts.conf │ ├── Dockerfile │ └── arns │ │ └── stix_fonts.csv └── amazon_linux_fonts │ ├── Dockerfile │ └── arns │ └── amazon_linux_fonts.csv ├── config └── regions.txt ├── Makefile ├── LICENSE ├── publish.sh └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # build output 2 | layer 3 | layer.zip 4 | -------------------------------------------------------------------------------- /fonts/stix_fonts/fonts.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /opt/usr/share/fonts/ 5 | /tmp/fonts/ 6 | 7 | -------------------------------------------------------------------------------- /config/regions.txt: -------------------------------------------------------------------------------- 1 | ap-east-1 2 | ap-northeast-1 3 | ap-northeast-2 4 | ap-south-1 5 | ap-southeast-1 6 | ap-southeast-2 7 | ca-central-1 8 | eu-central-1 9 | eu-north-1 10 | eu-west-1 11 | eu-west-2 12 | eu-west-3 13 | sa-east-1 14 | us-east-1 15 | us-east-2 16 | us-west-1 17 | us-west-2 18 | -------------------------------------------------------------------------------- /fonts/stix_fonts/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM amazonlinux:2 2 | 3 | RUN yum install -y \ 4 | rpmdevtools \ 5 | yum-utils 6 | 7 | WORKDIR /tmp 8 | 9 | # Download and extract stix-fonts 10 | RUN yumdownloader stix-fonts.noarch \ 11 | && rpmdev-extract *rpm 12 | 13 | WORKDIR /layer 14 | 15 | # Copy fonts and config for packaging 16 | RUN mkdir -p {etc/fonts,usr/share} \ 17 | && cp -aR /tmp/*/usr/share/font* usr/share 18 | 19 | COPY ./fonts.conf etc/fonts 20 | 21 | # Zip files 22 | ENV LAYER_ZIP="layer.zip" 23 | RUN zip -r $LAYER_ZIP etc usr \ 24 | && mv $LAYER_ZIP / -------------------------------------------------------------------------------- /fonts/amazon_linux_fonts/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM lambci/lambda-base 2 | 3 | RUN yum install -y zip 4 | 5 | WORKDIR /layer 6 | 7 | # Copy fonts and config for packaging 8 | RUN mkdir -p {etc/fonts,usr/share/{fonts,X11}} \ 9 | && cp -R /etc/fonts/* etc/fonts \ 10 | && cp -R /usr/share/fonts/* usr/share/fonts \ 11 | && cp -R /usr/share/X11/fonts* usr/share/X11 12 | 13 | # Change the font and cache directory 14 | RUN sed -i 's/\/usr\/share/\/opt\/usr\/share/g' etc/fonts/fonts.conf \ 15 | && sed -i 's/\/var\/cache/\/tmp\/cache/g' etc/fonts/fonts.conf 16 | 17 | # Zip files 18 | ENV LAYER_ZIP="layer.zip" 19 | RUN zip -r $LAYER_ZIP etc usr \ 20 | && mv $LAYER_ZIP / 21 | 22 | CMD ["/bin/bash"] -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: list 2 | list: 3 | @echo "Targets:" 4 | @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' 5 | 6 | define build 7 | ./build.sh -t $(1) 8 | endef 9 | 10 | define publish 11 | ./publish.sh -t $(1) -d $(2) 12 | endef 13 | 14 | .PHONY: stix_fonts_layer 15 | stix_fonts_layer: 16 | $(call build, fonts/stix_fonts/) 17 | 18 | .PHONY: publish_stix_fonts_layer 19 | publish_stix_fonts_layer: stix_fonts_layer 20 | $(call publish, fonts/stix_fonts/, "Stix fonts in AWS Lambda [https://www.stixfonts.org/]") 21 | 22 | .PHONY: amazon_linux_fonts_layer 23 | amazon_linux_fonts_layer: 24 | $(call build, fonts/amazon_linux_fonts/) 25 | 26 | .PHONY: publish_amazon_linux_fonts_layer 27 | publish_amazon_linux_fonts_layer: amazon_linux_fonts_layer 28 | $(call publish, fonts/amazon_linux_fonts/, "All fonts available in Amazon Linux runtime") 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Brandon Lim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /fonts/stix_fonts/arns/stix_fonts.csv: -------------------------------------------------------------------------------- 1 | Region,ARN 2 | ap-east-1,arn:aws:lambda:ap-east-1:347599033421:layer:stix-fonts:1 3 | ap-northeast-1,arn:aws:lambda:ap-northeast-1:347599033421:layer:stix-fonts:1 4 | ap-northeast-2,arn:aws:lambda:ap-northeast-2:347599033421:layer:stix-fonts:1 5 | ap-south-1,arn:aws:lambda:ap-south-1:347599033421:layer:stix-fonts:1 6 | ap-southeast-1,arn:aws:lambda:ap-southeast-1:347599033421:layer:stix-fonts:1 7 | ap-southeast-2,arn:aws:lambda:ap-southeast-2:347599033421:layer:stix-fonts:1 8 | ca-central-1,arn:aws:lambda:ca-central-1:347599033421:layer:stix-fonts:1 9 | eu-central-1,arn:aws:lambda:eu-central-1:347599033421:layer:stix-fonts:1 10 | eu-north-1,arn:aws:lambda:eu-north-1:347599033421:layer:stix-fonts:1 11 | eu-west-1,arn:aws:lambda:eu-west-1:347599033421:layer:stix-fonts:1 12 | eu-west-2,arn:aws:lambda:eu-west-2:347599033421:layer:stix-fonts:1 13 | eu-west-3,arn:aws:lambda:eu-west-3:347599033421:layer:stix-fonts:1 14 | sa-east-1,arn:aws:lambda:sa-east-1:347599033421:layer:stix-fonts:1 15 | us-east-1,arn:aws:lambda:us-east-1:347599033421:layer:stix-fonts:1 16 | us-east-2,arn:aws:lambda:us-east-2:347599033421:layer:stix-fonts:1 17 | us-west-1,arn:aws:lambda:us-west-1:347599033421:layer:stix-fonts:1 18 | us-west-2,arn:aws:lambda:us-west-2:347599033421:layer:stix-fonts:1 19 | -------------------------------------------------------------------------------- /fonts/amazon_linux_fonts/arns/amazon_linux_fonts.csv: -------------------------------------------------------------------------------- 1 | Region,ARN 2 | ap-east-1,arn:aws:lambda:ap-east-1:347599033421:layer:amazon_linux_fonts:1 3 | ap-northeast-1,arn:aws:lambda:ap-northeast-1:347599033421:layer:amazon_linux_fonts:1 4 | ap-northeast-2,arn:aws:lambda:ap-northeast-2:347599033421:layer:amazon_linux_fonts:1 5 | ap-south-1,arn:aws:lambda:ap-south-1:347599033421:layer:amazon_linux_fonts:1 6 | ap-southeast-1,arn:aws:lambda:ap-southeast-1:347599033421:layer:amazon_linux_fonts:1 7 | ap-southeast-2,arn:aws:lambda:ap-southeast-2:347599033421:layer:amazon_linux_fonts:1 8 | ca-central-1,arn:aws:lambda:ca-central-1:347599033421:layer:amazon_linux_fonts:1 9 | eu-central-1,arn:aws:lambda:eu-central-1:347599033421:layer:amazon_linux_fonts:1 10 | eu-north-1,arn:aws:lambda:eu-north-1:347599033421:layer:amazon_linux_fonts:1 11 | eu-west-1,arn:aws:lambda:eu-west-1:347599033421:layer:amazon_linux_fonts:1 12 | eu-west-2,arn:aws:lambda:eu-west-2:347599033421:layer:amazon_linux_fonts:1 13 | eu-west-3,arn:aws:lambda:eu-west-3:347599033421:layer:amazon_linux_fonts:1 14 | sa-east-1,arn:aws:lambda:sa-east-1:347599033421:layer:amazon_linux_fonts:1 15 | us-east-1,arn:aws:lambda:us-east-1:347599033421:layer:amazon_linux_fonts:1 16 | us-east-2,arn:aws:lambda:us-east-2:347599033421:layer:amazon_linux_fonts:1 17 | us-west-1,arn:aws:lambda:us-west-1:347599033421:layer:amazon_linux_fonts:1 18 | us-west-2,arn:aws:lambda:us-west-2:347599033421:layer:amazon_linux_fonts:1 19 | -------------------------------------------------------------------------------- /publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | usage() { 4 | cat </dev/null; then 58 | echo "aws command not found" 59 | exit 1 60 | fi 61 | 62 | rm -rf $ARN_DIR && mkdir -p $ARN_DIR 63 | 64 | echo "Region,ARN" >$ARN_FILE 65 | for region in $REGIONS; do 66 | printf "%s\n" "Region: $region" 67 | OUTPUT=$( 68 | aws lambda publish-layer-version \ 69 | --description "$LAYER_DESCRIPTION" \ 70 | --layer-name "$LAYER_NAME" \ 71 | --output text \ 72 | --query "[LayerVersionArn, Version]" \ 73 | --region "$region" \ 74 | --zip-file "fileb://$LAYER_ZIP" 75 | ) 76 | LAYER_VERSION_ARN=$(echo $OUTPUT | awk '{print $1}') 77 | LAYER_VERSION=$(echo $OUTPUT | awk '{print $2}') 78 | aws lambda add-layer-version-permission \ 79 | --action lambda:GetLayerVersion \ 80 | --layer-name "$LAYER_NAME" \ 81 | --output text \ 82 | --principal "*" \ 83 | --query "Statement" \ 84 | --region "$region" \ 85 | --statement-id public \ 86 | --version-number "$LAYER_VERSION" 87 | echo "$region,$LAYER_VERSION_ARN" >>$ARN_FILE 88 | printf "\n" 89 | done 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fonts on AWS Lambda Layer 2 | 3 | Allows fonts to be used in Lambda function. 4 | 5 | ## Getting Started 6 | 7 | 1. Add this layer to Lambda function by providing the [layer version ARN](#version-arns). 8 | 2. Add `FONTCONFIG_PATH=/opt/etc/fonts` [environment variable](#environment-variable) to Lambda function. 9 | 10 | ## Version ARNs 11 | 12 | ### Amazon Linux fonts 13 | 14 | These layers include fonts that were available in Amazon Linux operating system. 15 | 16 | | Region | ARN | 17 | | -------------- | --------------------------------------------------------------------- | 18 | | ap-east-1 | arn:aws:lambda:ap-east-1:347599033421:layer:amazon_linux_fonts:1 | 19 | | ap-northeast-1 | arn:aws:lambda:ap-northeast-1:347599033421:layer:amazon_linux_fonts:1 | 20 | | ap-northeast-2 | arn:aws:lambda:ap-northeast-2:347599033421:layer:amazon_linux_fonts:1 | 21 | | ap-south-1 | arn:aws:lambda:ap-south-1:347599033421:layer:amazon_linux_fonts:1 | 22 | | ap-southeast-1 | arn:aws:lambda:ap-southeast-1:347599033421:layer:amazon_linux_fonts:1 | 23 | | ap-southeast-2 | arn:aws:lambda:ap-southeast-2:347599033421:layer:amazon_linux_fonts:1 | 24 | | ca-central-1 | arn:aws:lambda:ca-central-1:347599033421:layer:amazon_linux_fonts:1 | 25 | | eu-central-1 | arn:aws:lambda:eu-central-1:347599033421:layer:amazon_linux_fonts:1 | 26 | | eu-north-1 | arn:aws:lambda:eu-north-1:347599033421:layer:amazon_linux_fonts:1 | 27 | | eu-west-1 | arn:aws:lambda:eu-west-1:347599033421:layer:amazon_linux_fonts:1 | 28 | | eu-west-2 | arn:aws:lambda:eu-west-2:347599033421:layer:amazon_linux_fonts:1 | 29 | | eu-west-3 | arn:aws:lambda:eu-west-3:347599033421:layer:amazon_linux_fonts:1 | 30 | | sa-east-1 | arn:aws:lambda:sa-east-1:347599033421:layer:amazon_linux_fonts:1 | 31 | | us-east-1 | arn:aws:lambda:us-east-1:347599033421:layer:amazon_linux_fonts:1 | 32 | | us-east-2 | arn:aws:lambda:us-east-2:347599033421:layer:amazon_linux_fonts:1 | 33 | | us-west-1 | arn:aws:lambda:us-west-1:347599033421:layer:amazon_linux_fonts:1 | 34 | | us-west-2 | arn:aws:lambda:us-west-2:347599033421:layer:amazon_linux_fonts:1 | 35 | 36 | ### Stix fonts 37 | 38 | These layers include [stix fonts](https://www.stixfonts.org/). 39 | 40 | | Region | ARN | 41 | | -------------- | ------------------------------------------------------------- | 42 | | ap-east-1 | arn:aws:lambda:ap-east-1:347599033421:layer:stix-fonts:1 | 43 | | ap-northeast-1 | arn:aws:lambda:ap-northeast-1:347599033421:layer:stix-fonts:1 | 44 | | ap-northeast-2 | arn:aws:lambda:ap-northeast-2:347599033421:layer:stix-fonts:1 | 45 | | ap-south-1 | arn:aws:lambda:ap-south-1:347599033421:layer:stix-fonts:1 | 46 | | ap-southeast-1 | arn:aws:lambda:ap-southeast-1:347599033421:layer:stix-fonts:1 | 47 | | ap-southeast-2 | arn:aws:lambda:ap-southeast-2:347599033421:layer:stix-fonts:1 | 48 | | ca-central-1 | arn:aws:lambda:ca-central-1:347599033421:layer:stix-fonts:1 | 49 | | eu-central-1 | arn:aws:lambda:eu-central-1:347599033421:layer:stix-fonts:1 | 50 | | eu-north-1 | arn:aws:lambda:eu-north-1:347599033421:layer:stix-fonts:1 | 51 | | eu-west-1 | arn:aws:lambda:eu-west-1:347599033421:layer:stix-fonts:1 | 52 | | eu-west-2 | arn:aws:lambda:eu-west-2:347599033421:layer:stix-fonts:1 | 53 | | eu-west-3 | arn:aws:lambda:eu-west-3:347599033421:layer:stix-fonts:1 | 54 | | sa-east-1 | arn:aws:lambda:sa-east-1:347599033421:layer:stix-fonts:1 | 55 | | us-east-1 | arn:aws:lambda:us-east-1:347599033421:layer:stix-fonts:1 | 56 | | us-east-2 | arn:aws:lambda:us-east-2:347599033421:layer:stix-fonts:1 | 57 | | us-west-1 | arn:aws:lambda:us-west-1:347599033421:layer:stix-fonts:1 | 58 | | us-west-2 | arn:aws:lambda:us-west-2:347599033421:layer:stix-fonts:1 | 59 | 60 | ## Environment variable 61 | 62 | Define the following environment variable for the Lambda function: 63 | 64 | | Key | Value | 65 | | ----------------- | ---------------- | 66 | | `FONTCONFIG_PATH` | `/opt/etc/fonts` | 67 | 68 | ## Build and Publish 69 | 70 | Refer to the Makefile to build and publish your own fonts layer. 71 | 72 | ### Scripts 73 | 74 | | Script | Description | 75 | | -------------- | ------------------------------------------------------------------- | 76 | | `./build.sh` | Build a new layer zip | 77 | | `./publish.sh` | Publish the layer zip to regions specified in `/config/regions.txt` | 78 | --------------------------------------------------------------------------------