Before you begin, I’ve had some bizarre issues getting this to work correctly on Windows. The zip file that gets uploaded to AWS has some odd permissions on it, which cause things to break. I recommend using OSX, Linux, or the WSL (Ubuntu 18.04 on Windows worked well).
git clone https://github.com/davidkryzaniak/zeplin-html-to-pdf.git htmltopdf and then
npm install to get all of the necessary packages.
All right! Let’s deploy it with
sam deploy --guided
After a few seconds, you will be asked to “Deploy this changeset?” Enter
Y and let it go.
Let it crunch for a few minutes, and if everything goes well, you should get the URL of the new endpoint.
We can prove that it’s working with a quick curl call
curl -X POST --data "<h1>hi</h1>" https://vvgwi7g1pe.execute-api.us-east-1.amazonaws.com/Prod
Grab the output and throw it into a base64 to PDF converter. Base64.Guru has a pretty sweet converter. https://base64.guru/converter/decode/pdf
One thing to keep in mind is that this endpoint does not have any security or protection. You will want to modify the index.js to include some custom checks, implement CORS in the API Gateway, or setup a VPC so only your machines can access it.