I am using AWS Lambda to resize my image in s3 bucket into different size variants using node js when an image is put into the s3 bucket.
It was working till yesterd
I had the exact same error message occur on a process that had been running flawlessly for the last 5 weeks. After speaking with AWS support today, I was informed that native library support for Imagemagick was removed from AWS Lambda due to the vulnerability that was found recently documented here https://imagetragick.com/.
I was told I would have to rebuild my Lambda function and bundle in my own version of the native library - https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/
The support representative confirmed that there had not been a public announcement of this change.
TLDR: If you had been using an AWS Lambda function that was dependent on the bundled in version of Imagemagick, as of 05/04/2016, it is now broken and probably will not work until you redeploy with your own built and maintained version of the library. May the fourth be with you...
https://alas.aws.amazon.com/ALAS-2016-699.html
"Note: This update contains an updated /etc/ImageMagick/policy.xml file that disables the EPHEMERAL, HTTPS, HTTP, URL, FTP, MVG, MSL, TEXT, and LABEL coders"
I changed my call from gm(my_url)
to gm(request(my_url))
and things seem to be working again. I.e I send a stream from a request() call to ImageMagick instead of letting ImageMagick try to download the image (which is disabled in ImageMagick's policy.xml, a file I can't modify).
Mitch Shields is correct, you now have to build / deploy it yourself onto AWS Lambda.
I have built a version that works for my project, and a NodeJS tool that will download it onto the lambda instance. The built tarbal is ~85mb, which is too large to package with your code, so you have to downloaded it onto lambda before running. It is stored in /tmp/imagemagick
, lambda attempts to cache the /tmp/
folder, so you shouldn't need to download it on every run.
GitHub Page: https://github.com/DoubleDor/imagemagick-prebuilt
Check the releases for the tarbal of the build ImageMagick https://github.com/DoubleDor/imagemagick-prebuilt/releases
It seems like your Lambda function has no access to your S3 bucket. Make sure that your function has an according IAM policy applied, e.g.:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::*"
]
}]
}
Although your problem has nothing to do with graphicsmagick, please note that AWS Lambda only comes with imagemagick installed. So unless you provide the graphicsmagick executables yourself make sure to use the imagemagic sub class:
var gm = require("gm").subClass({ imageMagick: true });
According to the AWS documentation: http://docs.aws.amazon.com/pt_br/lambda/latest/dg/current-supported-versions.html AWS Lambda still supporting imagemagick.
However, I had the same problem a few days ago, with a project that was working flawless. As the error message issues it seems to be a permission conflict while trying to read the S3 bucket rather than an imagemagick problem.
You can try changing the Bucket permissions Make a bucket public in Amazon S3.
Alternatively as a workaround you can always zip the image files with your lambda file and avoid such permissions conflics.