Created
January 17, 2025 08:48
-
-
Save lidio601/4b81c1768a25250113fc246dae316b44 to your computer and use it in GitHub Desktop.
ImageMagick AWS Lambda layer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
AssetHashType, | |
BundlingFileAccess, | |
BundlingOutput, | |
DockerImage, | |
RemovalPolicy, | |
} from 'aws-cdk-lib'; | |
import { Architecture, Code, LayerVersion } from 'aws-cdk-lib/aws-lambda'; | |
import { Construct } from 'constructs'; | |
// ============================================================ | |
// imagemagick lambda layer | |
// ============================================================ | |
// @see https://imagemagick.org/download/ | |
// TODO: update this to the latest version if needed | |
const VERSION = '7.1.1-43'; | |
const URL = `https://imagemagick.org/download/ImageMagick-${VERSION}.tar.gz`; | |
constlayer = new LayerVersion(this, 'Layer', { | |
compatibleArchitectures: [Architecture.X86_64], | |
removalPolicy: RemovalPolicy.DESTROY, | |
description: `imagemagick ${VERSION} downloaded from ${URL}`, | |
code: Code.fromAsset( | |
// this could be anything, | |
// we really just need to execute curl | |
__dirname, | |
{ | |
// the version is used as the asset hash | |
// so that we don't rebuild this every time | |
assetHash: VERSION, | |
assetHashType: AssetHashType.CUSTOM, | |
// we use this Docker container to download the QPDF binary | |
// from the Github releases page | |
bundling: { | |
bundlingFileAccess: BundlingFileAccess.VOLUME_COPY, | |
outputType: BundlingOutput.ARCHIVED, | |
image: DockerImage.fromBuild( | |
__dirname, | |
{ | |
file: 'ImageMagickLayer.Dockerfile', | |
} | |
), | |
}, | |
} | |
), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM public.ecr.aws/amazonlinux/amazonlinux:2 | |
RUN yum -y install libpng-devel libjpeg-devel libtiff-devel gzip tar gcc make gcc-c++ zip | |
WORKDIR /tmp | |
RUN cd /tmp && \ | |
curl https://imagemagick.org/download/ImageMagick-7.1.1-43.tar.gz --silent -L --output /tmp/ImageMagick.tar.gz && \ | |
mkdir -vp /tmp/ImageMagick && \ | |
tar xzvf ImageMagick.tar.gz -C /tmp/ImageMagick --strip-components=1 && \ | |
cd /tmp/ImageMagick && \ | |
./configure --prefix=/tmp/build --enable-shared=no --enable-static=yes --disable-dependency-tracking && \ | |
make && \ | |
make install && \ | |
cd /tmp/build && \ | |
mv bin/magick ./magick && \ | |
rm -Rfv bin etc include share && \ | |
mkdir -vp bin && \ | |
mv magick ./bin/magick && \ | |
cd /tmp/build/lib && \ | |
cp /usr/lib64/libtiff.so.5 . && \ | |
cp /usr/lib64/libjpeg.so.62 . && \ | |
cp /usr/lib64/libpng15.so.15 . && \ | |
cp /usr/lib64/libgomp.so.1 . && \ | |
cp /usr/lib64/libjbig.so.2.0 . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment