LoginSignup
0
1

More than 3 years have passed since last update.

wkhtmltopdfをECSで動かす

Posted at

背景

wkhtmltopdfを使ってPDF出力をさせたときにローカルで出力できても、実稼働環境でうまく動かず500エラーが出る事があった。
ローカルと実稼働環境の違いはnginxの有無とECSのOSで、nginxの方は別途検証し問題なさそうだった。

結論を言うとGemのバージョンの問題だったが、特定に少し時間かかったのでメモ。

実稼働環境

  • ECS
  • amzn-ami-2017.09.g-amazon-ecs-optimized(ami-872c4ae1)

問題の特定

実稼働環境のログを確認すると下記のようになっていた。

Command Error: /usr/local/bundle/gems/wkhtmltopdf-binary-0.12.5/bin/wkhtmltopdf:40:in `<main>': Invalid platform, must be running on Ubuntu 14.04/16.04/18.04 CentOS 6/7, Debian 8/9, or intel-based macOS (missing binary: /usr/local/bundle/gems/wkhtmltopdf-binary-0.12.5/bin/wkhtmltopdf_debian_10_amd64). (RuntimeError)
Error: PDF could not be generated!

実稼働環境で使用しているOSに対応してないよ!というエラーのよう…
debian_10_amd64とエラーにあるのでDebian 10に対応していないかを調べたところ、
同じようなことで悩んでいる人がいて、修正済みなのがわかった。
Please add support for debian 10 (buster)

wkhtmltopdf-binaryのバージョンが0.12.5.1以上であれば対応しているとのことなので早速反映。

修正

Gemfile
gem 'wkhtmltopdf-binary', '~>0.12.5.1'
gem 'wicked_pdf'
/config/initializers/wicked_pdf.rb
WickedPdf.config = {
 exe_path: "#{Gem.loaded_specs['wkhtmltopdf-binary'].full_gem_path}/bin/wkhtmltopdf"
}

上記の設定に変更後、無事に実稼働環境でもPDF出力ができた。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1