All we wanted to do was upload PDF documents to Lambda, a piece of serverless architecture offered by Amazon Web Services (AWS). Why we couldn’t make it work was creating headaches.
A client had asked us to improve their computing efficiency in uploading PDFs. Their previous method used the Elastic Beanstalk Instance in our Application Program Interface (API). It worked fine when uploading PDFs to an S3 bucket in AWS.
But, to maximize the client’s service while minimizing their operational footprint, we moved the procedure to the OS container Lambda – and that’s when we ran into a problem.
Initially it appeared the PDF files were uploading successfully to the S3 bucket. When completed, however, their file size almost doubled, and the pages were either blank or not even supported.
At first we thought the problem stemmed from some sort of file corruption. And since the API gateway doesn’t accept binary files, our only other option appeared to be converting the documents to binary when required.
We tried couple of ideas and deployed them. Unfortunately, nothing was working. So, after almost a week with no success, we were ready to contact the folks at AWS technical support.
While we were prepping for our phone call, we tried one more thing. On the Settings Screen in the API Gateway, we added “*/*” to the “Binary Media Types” field. The command “*/*” required the program to accept all aspects of the PDF files being uploaded. Then, just as we were beginning our conversation with Amazon, the system worked.
How it worked…
After discovering this fix, we now require that any API Gateway deployment from the AWS console has the mandatory command for every change in the settings.
What was going wrong – and what went right…
As mentioned, Lambda is an OS container operating within a virtual server. By design we couldn’t definitely observe how the program was interpreting our uploaded files – only that it was presenting them incorrectly.
By mandating that all PDF file elements be uploaded using the “*/*” command, we were able to ensure that the proper file elements were included. Thus, the uploaded PDF files began appearing correctly.