My goal is to run tesseract-ocr in AWS Lambda.
I've built an EC2 instance that attempts to mirror the Lambda environment. Executing tesseract without parameters succeeds in both environments. However, any attempt at substantive image processing, e.g. this code:
tess = child_process.exec('tesseract input.tif output -l eng -psm 1 hocr', function(error, stdout, stderr) {
...
runs successfully on my EC2 box, but fails in Lambda with this error:
Error: Command failed: Tesseract Open Source OCR Engine v3.04.00 with Leptonica
Error during processing.
at ChildProcess.exithandler (child_process.js:648:15)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:756:16)
at Process.ChildProcess._handle.onexit (child_process.js:823:5)
Error code: 1
Signal received: null
Lambda is assuming an IAM role with administrative privileges ({ "Effect": "Allow", "Action": "", "Resource": "" })
The "Error during processing" error is emitted by tesseract as a top level catch-all. I'm going to instrument tesseract and try to narrow the problem further.
How I got here:
I'd like to know what's going wrong - or how to diagnose it.
Thank you, Dave
Short answer: output must go in the /tmp dir, e.g.
tesseract input.tif /tmp/output -l eng -psm 1 hocr
Slightly longer answer: tesseract calls fopen wb under the hood, and apparently that is forbidden in /var/task.
I would have noticed this a few days ago, but Lambda has not been propagating my deployment packages. So, the one time I tried to put output in the /tmp dir, there was no effect - but that was b/c Lambda was executing a stale version of my function. Solution is to always delete-function before calling update-function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With