├── .gitignore ├── LICENSE.txt ├── Makefile ├── Makefile_gs ├── README-SAR.md ├── README.md └── template.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | log/ 2 | logs/ 3 | node_modules/ 4 | build/ 5 | result/ 6 | 7 | *.bak 8 | *.log 9 | *.pdf 10 | *.png 11 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Ghostscript license, see https://www.ghostscript.com/license.html 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 2 | 3 | DOCKER_IMAGE ?= lambci/lambda-base-2:build 4 | TARGET ?=/opt/ 5 | 6 | MOUNTS = -v $(PROJECT_ROOT):/var/task \ 7 | -v $(PROJECT_ROOT)result:$(TARGET) 8 | 9 | DOCKER = docker run -it --rm -w=/var/task/build 10 | build result: 11 | mkdir $@ 12 | 13 | clean: 14 | rm -rf build result 15 | 16 | bash: 17 | $(DOCKER) $(MOUNTS) --entrypoint /bin/bash -t $(DOCKER_IMAGE) 18 | 19 | all libs: 20 | $(DOCKER) $(MOUNTS) --entrypoint /usr/bin/make -t $(DOCKER_IMAGE) TARGET_DIR=$(TARGET) -f ../Makefile_gs init $@ 21 | 22 | 23 | STACK_NAME ?= ghostscript-layer 24 | 25 | result/bin/gs: all 26 | 27 | build/output.yaml: template.yaml 28 | aws cloudformation ${PROFILE} package --template $< --s3-bucket $(DEPLOYMENT_BUCKET) --output-template-file $@ 29 | 30 | deploy: build/output.yaml 31 | aws cloudformation ${PROFILE} deploy --template $< --stack-name $(STACK_NAME) 32 | aws cloudformation ${PROFILE} describe-stacks --stack-name $(STACK_NAME) --query Stacks[].Outputs --output table 33 | 34 | publish: 35 | sam publish -t build/output.yaml ${PROFILE} 36 | -------------------------------------------------------------------------------- /Makefile_gs: -------------------------------------------------------------------------------- 1 | # what to tell Ghostscript where it will expect to run from 2 | 3 | TARGET_DIR ?= /opt/ 4 | 5 | 6 | .ONESHELL: 7 | 8 | ## dev tool istallation 9 | init: 10 | 11 | 12 | ## GHOSTSCRIPT (https://www.ghostscript.com/) 13 | ## https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs927/ghostscript-9.27.tar.gz 14 | ## ------------------------------------------------------------------------------------------------------- 15 | GHOSTSCRIPT_VERSION=9.27 16 | GHOSTSCRIPT_VERSION_DIR=gs$(subst .,,$(GHOSTSCRIPT_VERSION)) 17 | GHOSTSCRIPT_SRC_FILE=ghostscript-${GHOSTSCRIPT_VERSION}.tar.gz 18 | GHOSTSCRIPT_SRC_DIR=$(subst .tar.gz,,$(GHOSTSCRIPT_SRC_FILE)) 19 | 20 | $(GHOSTSCRIPT_SRC_FILE): 21 | curl -OL https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/${GHOSTSCRIPT_VERSION_DIR}/${GHOSTSCRIPT_SRC_FILE} 22 | 23 | gs $(TARGET_DIR)bin/gs: $(GHOSTSCRIPT_SRC_FILE) 24 | tar -zxf $< 25 | cd ${GHOSTSCRIPT_SRC_DIR} 26 | ./configure \ 27 | --without-luratech \ 28 | --prefix=$(TARGET_DIR) 29 | make all 30 | make install 31 | 32 | all: $(TARGET_DIR)bin/gs 33 | -------------------------------------------------------------------------------- /README-SAR.md: -------------------------------------------------------------------------------- 1 | # Ghostscript Lambda Layer for Amazon Linux 2 AMIs 2 | 3 | Ghostscript AWS Lambda layer adding PDF files conversion support using ImageMagick. 4 | Bundles Ghostscript 9.27. 5 | 6 | As a prerequisite, add the ImageMagick support by deploying the 7 | [image-magick-lambda-layer](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:145266761615:applications~image-magick-lambda-layer) 8 | Lambda layer. Check out https://github.com/serverlesspub/imagemagick-aws-lambda-2 9 | for more information. 10 | 11 | This application provides a single output, `LayerVersion`, which points to a 12 | Lambda Layer ARN you can use with Lambda runtimes based on Amazon Linux 2 (such 13 | as the `nodejs10.x` runtime). 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ghostscript for AWS Lambda 2 | 3 | Scripts to compile Ghostscript (gs) for AWS Lambda instances powered by Amazon Linux 2.x, 4 | such as the `nodejs10.x` runtime, and the updated 2018.03 Amazon Linux 1 runtimes. 5 | 6 | 7 | ## Usage 8 | 9 | Absolutely the easiest way of using this is to pull it directly from the AWS Serverless 10 | Application repository into a CloudFormation/SAM application, or deploy directly from 11 | the Serverless Application Repository into your account, and then link as a layer. 12 | 13 | For more information, check out the 14 | [ghostscript-lambda-layer](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:154387959412:applications~ghostscript-lambda-layer) 15 | application in the Serverless App Repository. 16 | 17 | For manual deployments and custom builds, read below... 18 | 19 | 20 | ## Prerequisites 21 | 22 | * Docker desktop 23 | * Unix Make environment 24 | * AWS command line utilities (just for deployment) 25 | 26 | 27 | ## Compiling the code 28 | 29 | * start Docker services 30 | * `make all` 31 | 32 | There are two `make` scripts in this project. 33 | 34 | * [`Makefile`](Makefile) is intended to run on the build system, and just starts 35 | a Docker container matching the AWS Linux 2 environment for Lambda runtimes to 36 | compile Ghostscript using the second script. 37 | * [`Makefile_gs`](Makefile_gs) is the script that will run inside the container, 38 | and actually compile binaries. 39 | 40 | The output will be in the `result` dir. 41 | 42 | ### Configuring the build 43 | 44 | By default, this compiles a version expecting to run as a Lambda layer from 45 | `/opt`. You can change the expected location by providing a `TARGET` variable 46 | when invoking `make`. 47 | 48 | The default Docker image used is `lambci/lambda-base-2:build`. To use a different 49 | base, provide a `DOCKER_IMAGE` variable when invoking `make`. 50 | 51 | Modify the versions of libraries or Ghostscript directly in [`Makefile_gs`](Makefile_gs). 52 | 53 | 54 | ### Compiled info 55 | 56 | ``` 57 | ghostscript version 9.27 58 | ``` 59 | 60 | 61 | ## Deploying to AWS as a layer 62 | 63 | Run the following command to deploy the compiled result as a layer in your AWS account. 64 | 65 | ``` 66 | make deploy DEPLOYMENT_BUCKET= [PROFILE="--profile "] 67 | ``` 68 | 69 | 70 | ### Configuring the deployment 71 | 72 | By default, this uses `ghostscript-layer` as the stack name. Provide a 73 | `STACK_NAME` variable when calling `make deploy` to use an alternative name. 74 | 75 | 76 | ## Additional Info 77 | 78 | For more information, check out: 79 | 80 | * https://www.ghostscript.com/ 81 | 82 | 83 | ## Author 84 | 85 | Tomislav Capan 86 | 87 | 88 | ## License 89 | 90 | * These scripts: [MIT](https://opensource.org/licenses/MIT) 91 | * Ghostscript: 92 | * Contained libraries all have separate licenses, check the respective web sites for more information 93 | -------------------------------------------------------------------------------- /template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: > 4 | Ghostscript AWS Lambda layer adding PDF files conversion support using ImageMagick. 5 | 6 | As a prerequisite, add the ImageMagick support by deploying the 7 | [image-magick-lambda-layer](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:145266761615:applications~image-magick-lambda-layer) 8 | Lambda layer. 9 | 10 | Check out https://github.com/serverlesspub/imagemagick-aws-lambda-2 11 | for more information. 12 | Resources: 13 | GhostscriptLayer: 14 | Type: AWS::Serverless::LayerVersion 15 | Properties: 16 | LayerName: ghostscript 17 | Description: Ghostscript AWS Lambda layer adding PDF files conversion support using ImageMagick 18 | ContentUri: result/ 19 | CompatibleRuntimes: 20 | - nodejs10.x 21 | LicenseInfo: https://www.ghostscript.com/license.html 22 | RetentionPolicy: Retain 23 | 24 | Outputs: 25 | LayerVersion: 26 | Description: Layer ARN Reference 27 | Value: !Ref GhostscriptLayer 28 | 29 | Metadata: 30 | AWS::ServerlessRepo::Application: 31 | Name: ghostscript-lambda-layer 32 | Description: > 33 | Ghostscript AWS Lambda layer adding PDF files conversion support using ImageMagick. 34 | Bundles Ghostscript 9.27. 35 | Author: Tomislav Capan 36 | SpdxLicenseId: MIT 37 | LicenseUrl: LICENSE.txt 38 | ReadmeUrl: README-SAR.md 39 | Labels: ['layer', 'pdf', 'lambda', 'ghostscript', 'gs'] 40 | HomePageUrl: https://github.com/zappan/ghostscript-lambda-layer 41 | SemanticVersion: 9.27.0 42 | SourceCodeUrl: https://github.com/zappan/ghostscript-lambda-layer 43 | --------------------------------------------------------------------------------