Back story, I am updating a docker container, lambda function, to handle convert an xls/xlsx and all of its sheets to pdf. Here is what os is running in the container:
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="amazon linux.com/"
VARIANT_ID="202308151228-2.0.1114.0"
The docker file is very simple.
FROM public .ecr .aws/lambda/python:latest
COPY requirements.txt .
RUN python -m pip install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
COPY app.py ${LAMBDA_TASK_ROOT}
CMD [ "app.lambda_handler" ]
Here is the basic requirements.txt
boxsdk[jwt]
urllib3<2
Spire.XLS-for-Python
plum-dispatch==1.7.4
Within this container we have been evaluating open source conversion software, but the quality of these are poor. The basic python below is what is being tested.
- Code: Select all
def convert_sheets_to_pdf_SPIRE(input_file, output_file):
workbook = Workbook()
workbook.LoadFromFile(input_file)
for sheet in workbook.Worksheets:
pageSetup = sheet.PageSetup
pageSetup.TopMargin = 0.3
pageSetup.BottomMargin = 0.3
pageSetup.LeftMargin = 0.3
pageSetup.RightMargin = 0.3
workbook.ConverterSetting.SheetFitToPage = True
workbook.SaveToFile(output_file, FileFormat.PDF)
workbook.Dispose()
print(f'File "{input_file}" converted to "{output_file}" and saved')
This works great when run locally on windows running python, but update the lambda source to use this function, build and run the container we get this in our docker logs:
AND this response after a web request from the containerGetDllLibXls().Workbook_CreateWorkbook.restype = c_void_p_PIREPath + pdfFile)orkbook_CreateWorkbook'
{"errorMessage": "'NoneType' object has no attribute 'Workbook_CreateWorkbook'", "errorType": "AttributeError", "requestId": "1f538bd0-c649-448e-b9f1-49b322f8fba6", "stackTrace": [" File \"/var/task/app.py\", line 156, in lambda_handler\n convert_sheets_to_pdf_SPIRE(input_file, output_file)\n", " File \"/var/task/app.py\", line 73, in convert_sheets_to_pdf_SPIRE\n workbook = Workbook()\n", " File \"/var/task/plum/function.py\", line 642, in __call__\n return self.f(self.instance, *args, **kw_args)\n", " File \"/var/task/plum/function.py\", line 592, in __call__\n return _convert(method(*args, **kw_args), return_type)\n", " File \"/var/task/spire/xls/Workbook.py\", line 17, in __init__\n GetDllLibXls().Workbook_CreateWorkbook.restype = c_void_p\n"]}
This looks like there are other dependencies need to run 'Spire.XLS - Python' within a container.
Any ideas on next steps or what is missing?