I'm trying to run serverless LibreOffice based on this tutorial. Here is the full python lambda function:
import boto3
import os
s3_bucket = boto3.resource("s3").Bucket("lambda-libreoffice-demo")
os.system("curl https://s3.amazonaws.com/lambda-libreoffice-demo/lo.tar.gz -o /tmp/lo.tar.gz && cd /tmp && tar -xf /tmp/lo.tar.gz")
convertCommand = "instdir/program/soffice --headless --invisible --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --convert-to pdf --outdir /tmp"
def lambda_handler(event,context):
inputFileName = event['filename']
# Put object wants to be converted in s3
with open(f'/tmp/{inputFileName}', 'wb') as data:
s3_bucket.download_fileobj(inputFileName, data)
# Execute libreoffice to convert input file
os.system(f"cd /tmp && {convertCommand} {inputFileName}")
# Save converted object in S3
outputFileName, _ = os.path.splitext(inputFileName)
outputFileName = outputFileName + ".pdf"
f = open(f"/tmp/{outputFileName}","rb")
s3_bucket.put_object(Key=outputFileName,Body=f,ACL="public-read")
f.close()
The response when running the full scripts is:
"errorMessage": "ENOENT: no such file or directory, open '/tmp/example.pdf'",
So I began to debug it row by row.
Based on my debug prints, it seems that it fails right on the start, when trying to extract the binary on the second row:
os.path.exists('/tmp/lo.tar.gz') // => true
os.path.exists('/tmp/instdir/program/soffice.bin') // => false
So it looks like the tar is the problematic part there.
If I download the file from S3 and run the tar command locally it seems to extract the file just fine.
Tried with node, python 3.8, python 3.6.
Also tried it with and without the layer (and the /opt/lo.tar.br path) as described here.