Closed BrunIF closed 5 years ago
import boto3
import os
s3_bucket = boto3.resource("s3").Bucket("my-bucket")
os.system("pip install boto3 && curl https://s3-us-west-2.amazonaws.com/my-bucket/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()
My mistake. I don't copy source file to S3.
Run command
and got the answer
The function was created manually and via CLI. The same problem.