I want to create simple python aws lambda function which works with pdf files.
I followed the instruction from aws docs and created docker image, pushed it to AWS ECR and created lambda basing on it.
I want to send file in POST request body with content type application/pdf
.Then i added api gateway in front of it and added media type application/pdf
.
But i still get this error. Does anybody knows any solutions?
Here is my lambda code
import jsonimport base64import pdfplumberimport ioimport loggingdef lambda_handler(event, context): try: pdf_data = base64.b64decode(event["body"]) pdf_file = io.BytesIO(pdf_data) with pdfplumber.open(pdf_file) as pdf: tables = [ page.extract_tables( table_settings={"vertical_strategy": "lines_strict","horizontal_strategy": "lines_strict", } ) for page in pdf.pages ] return {"statusCode": 200,"body": json.dumps( {"message": "Tables extracted successfully", "tables": tables} ), } except Exception as e: return {"statusCode": 500, "body": json.dumps({"error": str(e)})}
And here is my dockerfile
FROM public.ecr.aws/lambda/python:3.9COPY requirements.txt ${LAMBDA_TASK_ROOT}RUN pip install -r requirements.txtCOPY src/* ${LAMBDA_TASK_ROOT}CMD ["main.lambda_handler"]