LoginSignup
1
1

More than 1 year has passed since last update.

Lambdaで I/O Errorが発生した場合の対応

Posted at

はじめに

個人的な備忘録が目的です。
言語は Python のみですが、考え方は他の言語にも流用できるかなと思います。

問題点

Lambdaでファイル作成系のコマンドを実行すると、たまに I/O Error 発生したりします。
例えば、 poppler にある pdftohtml を実行すると、

pdftohtml test.pdf output
I/O Error: Couldn't open html file 'outputs.html

原因は、Lambdaではカレントディレクトリにファイルを作成することができないからです。

対応策

上記のStackOverflowの記事にも書かれている通り、 /tmp に作成するようにしたら良いです。
subprocess を使う場合は、以下のような感じですね。

command_list = ["pdftohtml", "-s", "-i", "test.pdf", "output"]
process = subprocess.Popen(command_list,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT,
                           cwd="/tmp",
                           universal_newlines=True)

さいごに

何かありましたら、コメント頂けると助かります。

1
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
1
1