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.
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 a
wire-o.yml
file at root. - Define
s3BucketName
variable in thewire-o.yml
file. This is set in theserverless.yml
file and used in the JavaScript code.
s3BucketName: "s3-bucket-name-goes-here"
This command will compile JavaScript with Babel, and deploy the app using Serverless:
npm run deploy
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"
}
You can view how the Lambda function is performing by going into the AWS Console and viewing logs in Cloudwatch.