Coder Social home page Coder Social logo

wire-o's Introduction

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:

  1. Install pip first if you don't have it already with sudo easy_install pip (on Mac OSX)
  2. Install the CLI with sudo -H pip install awscli --upgrade --ignore-installed six (on Mac OSX)

After the AWS CLI is installed...

  1. Find your Access Key & Secret Access Keys, and make sure you have the permissions you need to access AWS.
  2. Run aws configure.
  3. Put in the Access & Secret Access keys.
  4. Install the Serverless framework.

Create wire-o.yml and set bucket name variable

  1. Create a wire-o.yml file at root.
  2. Define s3BucketName variable in the wire-o.yml file. This is set in the serverless.yml file 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.

wire-o's People

Contributors

dependabot[bot] avatar jackjennings avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wire-o's Issues

Exchange PDFMerge for Ghostscript

The gs command should be pre-installed on linux, and give us a good utility for merging PDFs without the overhead or bugs that are part of the PDFMerge library.

https://www.linux.com/news/putting-together-pdf-files
http://stackoverflow.com/questions/8158584/ghostscript-to-merge-pdfs-compresses-the-result

This isn't a crucial change, but would be nice to shed the dependency on this library and shell out to Ghostscript to do the actual merge. This would be a better foundation to start adding additional functionality like stamping pages with a timecode, or adding page numbers—which seems to be supported by GS.

Add general description of package

After the Wire-O heading in the readme, a short (one sentence) description should explain the main points: AWS Lambda, JavaScript, merge PDFS, ?.

Add NPM script for deploying

It would be nice to be able to compile and deploy in one step. Currently, deployment consists of building the final bundle, and then running the deployment command.

Ideally, this should be one step, e.g. npm run deploy.

Unable to execute becuase of missing module 'babel-runtime/regenerator'

This is the repsonse from the API
{
"errorMessage": "Cannot find module 'babel-runtime/regenerator'",
"errorType": "Error",
"stackTrace": [
"Module.require (module.js:497:17)",
"require (internal/module.js:20:19)",
"Object. (/var/task/dist/app.js:3:20)",
"Module._compile (module.js:570:32)",
"Object.Module._extensions..js (module.js:579:10)",
"Module.load (module.js:487:32)",
"tryModuleLoad (module.js:446:12)",
"Function.Module._load (module.js:438:3)"
]
}
I am completley new to babel and npm, so tried some links i found in web by changing babel versions but it did not solve the issue.

Cloud watch logs :
Unable to import module 'dist/app': Error
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/var/task/dist/app.js:3:20)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

Is this related to new babel version?

My pacagke.json diff
},
"dependencies": {
"aws-sdk": "^2.6.9",

  • "babel": "^6.23.0",
    "bluebird": "^3.4.6",
    "mkdirp": "^0.5.1",
    "node-uuid": "^1.4.7",
    @@ -19,14 +20,17 @@
    },
    "devDependencies": {
    "aws-lambda-mock-context": "^3.0.0",
  • "babel-cli": "^6.18.0",
  • "babel-cli": "^6.26.0",
    "babel-eslint": "^7.0.0",
    "babel-plugin-transform-flow-strip-types": "^6.18.0",
  • "babel-plugin-transform-regenerator": "^6.26.0",
  • "babel-plugin-transform-runtime": "^6.23.0",
    "babel-plugin-transform-runtime ": "^6.23.0",
    "babel-polyfill": "^6.16.0",
  • "babel-preset-es2015": "^6.18.0",
  • "babel-preset-stage-2": "^6.18.0",
  • "babel-preset-es2015": "^6.24.1",
  • "babel-preset-stage-2": "^6.24.1",
    "babel-register": "^6.18.0",
  • "babel-runtime": "^6.26.0",
    "chai": "^3.5.0",
    "eslint": "^3.8.1",
    "eslint-plugin-flowtype": "^2.25.0",

ServerlessError is not authorized to perform... how to solve?

$ npm run deploy

[email protected] deploy /Users/xxx/Documents/www/node/wire-o
babel lib --out-dir dist && serverless deploy

lib/app.js -> dist/app.js
lib/download.js -> dist/download.js
lib/downloadPdfs.js -> dist/downloadPdfs.js
lib/formatResponse.js -> dist/formatResponse.js
lib/mergePdfs.js -> dist/mergePdfs.js
lib/storePdf.js -> dist/storePdf.js
lib/tmpDirectory.js -> dist/tmpDirectory.js
lib/uploadToS3.js -> dist/uploadToS3.js

Error --------------------------------------------------

 ServerlessError: ServerlessError: User: arn:aws:iam::XXX:user/mscore
 is not authorized to perform: cloudformation:DescribeStackResources
 on resource: arn:aws:cloudformation:us-east-1:XXX:stack/wire-o-dev/*

 For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless

Your Environment Information -----------------------------
OS: darwin
Node Version: 6.9.5
Serverless Version: 1.11.0
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.