Recently the ‘GD’ extension was added to Bref, allowing images to be created.
Continuing on that theme, the ‘imagick’ extension was also going to be a nice addition.
To add it in, you need to do the following;
- Checkout bref from Github
- Add in the lines suggested here, into the ‘runtimes/php-intermediary.Dockerfile’; https://github.com/brefphp/bref/issues/267#issuecomment-476578009
- Go into the ‘runtimes’ dir and run ‘make layers’
This will make a few zip files in the ‘runtimes/export’ dir, which are the layers (runtimes) which need to be uploaded to Lambda. That can be done by;
aws lambda publish-layer-version --region=ap-southeast-2 --layer-name=php-73-fpm-with-imagick --zip-file fileb://php-73-fpm.zip --compatible-runtimes provided --output text
aws lambda publish-layer-version --region=ap-southeast-2 --layer-name=php-73-with-imagick --zip-file fileb://php-73.zip --compatible-runtimes provided --output text
Don’t forget to change the region name in the above commands!
Once that’s done, you’ll see the layers in the ‘Lambda’ ‘Layers’ page. Copy the ARN from there into your serverless .yml file, and away you go!
Don’t forget to enable the extension – this is done by creating a ‘php.ini’ file at /php/conf.d/php.ini (in your code-base), with the following;
extension=imagick
If you want to make sure it works, include the following in your PHP file and it’ll output a full list of info about the PHP environment, including a section on imagick if it’s been enabled & setup properly.
Enjoy!