Graphicsmagick在使用Node.js和S3的Elastic Beanstalk中不起作用 [英] Graphicsmagick not working in Elastic Beanstalk with nodejs and S3
问题描述
我正在使用nodejs和graphicsmagick处理带有文本的图像,然后将最终的jpg流式传输到S3.
I'm using nodejs and graphicsmagick to process images with text, then streaming the final jpg to S3.
使用邮递员,我能够在本地主机上测试此流,并且一切正常.但是,现在我将其移至Elastic Beanstalk时遇到了问题.当我发布到端点时,它将一个空白文件上传到S3,并且EB中没有记录错误.我认为它与软件有关,但是有点卡住了.任何建议表示赞赏!谢谢!
Using postman, I was able to test this flow on my localhost and everything works fine. However, I'm having issues now that I moved it to Elastic Beanstalk. When I post to the endpoint, it uploads a blank file to S3 and there are no errors logged in EB. I think it has something to do with the software but am a bit stuck. Any advice appreciated! Thanks!
顶部文件来自localhost,底部文件来自Elastic Beanstalk: http://cl.ly/image/0O231k171N0W
var gm = require('gm');
var appRoot = require('app-root-path').path;
function createImage(caption, res) {
var originalImage = '/images/2015-02-24.jpg';
var textColor = 'white';
gm(appRoot + originalImage)
.fill(textColor)
.font( appRoot + '/fonts/BentonSans-Book.otf')
.drawText(0, 0, caption, 'Center')
.stream(function(err, stdout, stderr) {
sendToS3(err, stdout, stderr, originalImage, res);
});
}
function sendToS3(err, stdout, stderr, originalImage, client_response) {
var imageName = shortId.generate();
var buff = new Buffer('');
stdout.on('data', function(data) {
buff = Buffer.concat([buff, data]);
});
stdout.on('end', function(data) {
var data = {
Bucket: S3_bucket,
Key: imageName + '.jpg',
Body: buff,
ContentType: mime.lookup(originalImage)
};
s3.putObject(data, function(err, res) {
client_response.send('done');
});
});
}
================================================ ================
===============================================================
我没有将其流式传输到S3,而是将其更改为直接写入文件系统.在AWS EB日志中引发的错误是:
Instead of streaming to S3, I changed it to write directly to the filesystem. The error being thrown in AWS EB logs is:
err { [Error: Command failed: gm convert: Request did not return an
image.] code: 1, signal: null }
我相信我缺少ImageMagick的某些依赖项.有什么想法吗?
I believe I'm missing some dependencies for ImageMagick. Any thoughts?
这是通过在我的本地终端中运行 convert --version 来实现的:
This is from running convert --version in my local terminal:
Version: ImageMagick 6.8.9-7 Q16 x86_64 2014-08-31
http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg ltdl lzma png xml zlib
这是通过在我的EC2实例中运行 convert --version (代表"部分为空)来实现的:
This is from running convert --version in my EC2 instance (The Delegates section is empty):
Version: ImageMagick 6.9.1-1 Q16 x86_64 2015-04-10
http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: DPC OpenMP
Delegates (built-in):
推荐答案
如何在ElasticBeanstalk的EC2实例上安装GraphicsMagick?您是否正在使用自定义AMI?默认的AMI(至少是我使用过的AMI)没有GraphicsMagick,但我对ImageMagick也不了解.
How are you installing GraphicsMagick on your EC2 instance in ElasticBeanstalk? Are you using a custom AMI? The default AMI (at least the ones I've used) didn't have GraphicsMagick, I don't know about ImageMagick though.
您可以使用容器命令与yum一起安装软件包.我在需要GraphicsMagick的项目中使用了以下代码.
You can use container commands to install packages with yum. I used the one below on a project where I needed GraphicsMagick.
在项目的根目录下创建一个名为".ebextensions"的文件夹.在该文件夹内,创建一个名为"package.config"的文件,其中包含以下内容:
Create a folder at the root of your project with the name ".ebextensions." Inside of that folder, create a file called "package.config" with the following contents:
commands:
01-command:
command: yum install -y --enablerepo=epel GraphicsMagick
这将在创建实例时安装它.我觉得这应该可以解决您的问题,否则,您可能希望使用yum的命令行选项来使用相同版本或也安装委托:
This will install it when the instance is created. I have a feeling this should resolve your issue, if not you may want to use command line options for yum to use the same version or install the delegates as well:
commands:
01-command:
command: yum install -y --enablerepo=epel GraphicsMagick
02-command:
command: yum install -y --enablerepo=epel GraphicsMagick-devel
这篇关于Graphicsmagick在使用Node.js和S3的Elastic Beanstalk中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!