1.3.3 • Published 3 years ago

mov-pdf-generator v1.3.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

PDF Generator

Overview

The application generates a report pdf using puppeteer and save PDF in an S3 Bucket.

Scope and Limitation

Receives an external trigger such as lambda or API Gateway to generate report pdf. Can generate multiple PDFs at once.

Out of scope

To be updated

Dependencies

Applications / Serverless Application Dependent to mov-pdf-generator

AWS Services

  • Lambda
  • Step Function
  • Simple Notification Service
  • S3
  • Websockets

Single report PDF step function - how does it work?

MOV PDF Generator Illustration

  1. A lambda starts mov-pdfGeneratorStateMachine-{stage} execution with input as reportId and passthrough* (optional). A passthrough is any data passed from the requester to the end of the step function and possibly can be use by another service.
  2. mov-pdfGeneratorStateMachine-{stage} is composed of getReport, getReportData and executePDFGenerator.
  3. Upon successful execution a message will be published to SNS and all subscribers to the SNS will receive the image. subscribers can be lambda, SQS, email or http/s
  4. Upon invalid execution the error information will be send to recipients defined in AWS SNS console

Public interface

PDF Generator can be invoked using websockets.

  1. Connect to websocket service wss://c2sa43bpif.execute-api.us-east-1.amazonaws.com/STAGE?token=YOUR_METJWT_TOKEN
  2. Service consumes generateReportPdf action only together with reportId payload. Example: {"action": "generateReportPdf", "reportId": "YOUR_REPORT_ID"}
  3. Once the report is generated, service emits generateReportSucceeded.
  4. Your application should handle all possible actions.

Multiple report PDFs - how does it work

Multiple PDFs wrapper

Step function above executes multiple step functions for each reportId. Then it waits for all of them to be finished

  1. To start execution of multiple PDFs you have specify array of report ids. Such as:
    {
    	"reportIds": ["3f0aebef-30e7-405e-bce1-ba116242a9be", "8a829a00-fdcc-4d81-b37e-887402b81493"],
    	"passThroughProps": {}
    }
  2. Wait 10 seconds
  3. Check if all step functions executed by this wrapper are finished (succeeded)
  4. If false wait another 10 seconds and repeat. If true Succeed step function

Run locally, test and deploy

  • yarn start will run local serverless configuration
  • yarn test will run integration tests
  • yarn deploy-{stage} e.g. yarn deploy-test
  • serverless deploy -s {stage} function -f {lambdaFunctionName} to deploy a function

Workflow - from official serverless site

Read this on the main serverless docs site

Cheat Sheet

A handy list of commands to use when developing with the Serverless Framework.

Deploy All

Use this when you have made changes to your Functions, Events or Resources in serverless.yml or you simply want to deploy all changes within your Service at the same time.

serverless deploy -s [STAGE NAME] -r [REGION NAME] -v

Deploy Function

Use this to quickly overwrite your AWS Lambda code on AWS, allowing you to develop faster.

serverless deploy function -f [FUNCTION NAME] -s [STAGE NAME] -r [REGION NAME]

Invoke Function

Invokes an AWS Lambda Function on AWS and returns logs.

serverless invoke -f [FUNCTION NAME] -s [STAGE NAME] -r [REGION NAME] -l

Streaming Logs

Open up a separate tab in your console and stream all logs for a specific Function using this command.

serverless logs -f [FUNCTION NAME] -s [STAGE NAME] -r [REGION NAME] -t

Cleanup

If at any point, you no longer need your service, you can run the following command to remove the Functions, Events and Resources that were created, and ensure that you don't incur any unexpected charges.

serverless remove