wire-o
wire-o copied to clipboard
AWS Lambda function for PDF binding
Wire-O
Wire-O is a serverless JavaScript (ES2015) app that lets you quickly set up an API on AWS to merge PDFs and send back links of merged PDFs.
Uses Serverless framework, AWS Lambda (Node 6.10), AWS API Gateway, AWS S3, and PDFMerge.
Setup and Deployment
First things first: Get the tools you need
You can use the AWS Console, but the AWS CLI allows for the scripting of Lambda uploads. Here's how to get it:
- Install pip first if you don't have it already with
sudo easy_install pip(on Mac OSX) - Install the CLI with
sudo -H pip install awscli --upgrade --ignore-installed six(on Mac OSX)
After the AWS CLI is installed...
- Find your Access Key & Secret Access Keys, and make sure you have the permissions you need to access AWS.
- Run
aws configure. - Put in the Access & Secret Access keys.
- Install the Serverless framework.
Create wire-o.yml and set bucket name variable
- Create a
wire-o.ymlfile at root. - Define
s3BucketNamevariable in thewire-o.ymlfile. This is set in theserverless.ymlfile and used in the JavaScript code.
s3BucketName: "s3-bucket-name-goes-here"
Deployment
This command will compile JavaScript with Babel, and deploy the app using Serverless:
npm run deploy
The Endpoint
After you have deployed Wire-O, you will have created an API Gateway endpoint that accepts POST requests and triggers a Lambda Function to run. You will see the URL in your console output, which will look something like this:
https://o64722rmyh.execute-api.us-east-1.amazonaws.com/dev/merge
With this endpoint, the JSON request body accepts an array of pdfUrls:
{
"pdfUrls": [
"https://s3.amazonaws.com/superglue/PCAH_PDF_TEMPLATE.pdf",
"https://s3.amazonaws.com/superglue/hello.pdf"
]
}
The JSON response body provides a link to the merged PDF hosted on S3:
{
"mergedPdf": "https://s3.amazonaws.com/superglue/merged/1ed989e5-026d-41f6-917f-953b4fd35bd8.pdf"
}
Monitoring
You can view how the Lambda function is performing by going into the AWS Console and viewing logs in Cloudwatch.