├── .gitignore
├── .jshintrc
├── LICENSE
├── README.md
├── buildspec.yml
├── docs
├── .nojekyll
├── _coverpage.md
├── _sidebar.md
├── content
│ ├── _sidebar.md
│ ├── api
│ │ ├── _sidebar.md
│ │ ├── components.md
│ │ └── paths.md
│ ├── api_reference.md
│ ├── concepts
│ │ └── _sidebar.md
│ ├── quick_start.md
│ ├── release_notes.md
│ └── releases
│ │ ├── 1.0.5.md
│ │ ├── 1.1.0.md
│ │ ├── 1.1.1.md
│ │ ├── 2.0.0.md
│ │ ├── 2.1.0.md
│ │ ├── 2.1.1.md
│ │ ├── 3.0.0.md
│ │ ├── 3.0.1.md
│ │ └── _sidebar.md
├── index.html
├── static
│ └── openapi.yml
└── styles
│ └── override.css
├── lerna.json
├── openapi.yml
├── package.json
├── packages
└── api
│ ├── Makefile
│ ├── README.md
│ ├── common
│ ├── api
│ │ └── PrinterFailureTypes.js
│ └── aws
│ │ └── LambdaHelper.js
│ ├── gulpfile.js
│ ├── log4js.config.js
│ ├── package.json
│ ├── print
│ ├── print.js
│ └── test
│ │ ├── print.5MB.json
│ │ └── print.json
│ ├── serverless.yml
│ ├── service
│ ├── test
│ │ └── version.json
│ └── version.js
│ └── webpack.config.js
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .serverless
3 | .webpack
4 | node_modules
5 | out.pdf
6 |
7 | chrome-aws-lambda
8 |
9 | layers
10 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "esversion": 9,
3 | "validthis": true,
4 | "-W018": true
5 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2020, Barchart.com, Inc., http://www.barchart.com/
2 |
3 | This software consists of voluntary contributions made by many
4 | individuals. For exact contribution history, see the revision history
5 | available at https://github.com/barchart/barchart-common-js
6 |
7 | The following license applies to all parts of this software.
8 |
9 | ====
10 |
11 | Permission is hereby granted, free of charge, to any person obtaining
12 | a copy of this software and associated documentation files (the
13 | "Software"), to deal in the Software without restriction, including
14 | without limitation the rights to use, copy, modify, merge, publish,
15 | distribute, sublicense, and/or sell copies of the Software, and to
16 | permit persons to whom the Software is furnished to do so, subject to
17 | the following conditions:
18 |
19 | The above copyright notice and this permission notice shall be
20 | included in all copies or substantial portions of the Software.
21 |
22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # @barchart/aws-lambda-pdf-generator
2 |
3 | [](https://github.com/barchart/aws-lambda-pdf-generator)
4 | [](https://lerna.js.org/)
5 |
6 | **Generate PDF files from HTML documents.**
7 |
8 | _Simply ```POST``` an HTML document to a web service and receive an ```application/pdf``` document in response._
9 |
10 | ### Implementation
11 |
12 | * The [Serverless](https://www.serverless.com/) framework creates a web service using [AWS API Gateway](https://aws.amazon.com/api-gateway/) and [AWS Lambda](https://aws.amazon.com/lambda/).
13 | * The web service uses [Puppeteer](https://github.com/puppeteer/puppeteer) and [Chromium](https://www.chromium.org/) to render an HTML document as a PDF file.
14 |
15 | ### Documentation
16 |
17 | Complete documentation for installation and operation can be found [here](https://barchart.github.io/aws-lambda-pdf-generator/#/).
18 |
19 | ### Technical Notes
20 |
21 | **ARM Architecture (2023/08/31, v3.0.0)**
22 |
23 | > It would be nice to use ARM architecture for AWS Lambda functions (and use Apple silicon locally). However, the [`@sparticuz/chromium`](https://github.com/Sparticuz/chromium) project has not yet added support. See the comments [here](https://github.com/Sparticuz/chromium#running-locally--headlessheadful-mode).
24 |
25 | ### License
26 |
27 | This software is provided under the MIT license.
28 |
--------------------------------------------------------------------------------
/buildspec.yml:
--------------------------------------------------------------------------------
1 | version: 0.2
2 |
3 | phases:
4 | install:
5 | runtime-versions:
6 | nodejs: 20.x
7 |
8 | pre_build:
9 | commands:
10 | - npm install yarn --location=global
11 | - yarn install
12 |
13 | build:
14 | commands:
15 | - yarn lint
16 | - cd packages/api
17 | - make all
18 |
--------------------------------------------------------------------------------
/docs/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/barchart/aws-lambda-pdf-generator/646117963b2ecc42543c6bc4560d1854b3f0173a/docs/.nojekyll
--------------------------------------------------------------------------------
/docs/_coverpage.md:
--------------------------------------------------------------------------------
1 | # @barchart/aws-lambda-pdf-generator 3.0.1
2 |
3 | > Serverless application that coverts HTML to PDF
4 |
5 | [Quick Start](/content/quick_start)
6 |
--------------------------------------------------------------------------------
/docs/_sidebar.md:
--------------------------------------------------------------------------------
1 | * [Quick Start](/content/quick_start)
2 |
3 | * [API Reference](/content/api_reference)
4 |
5 | * [Release Notes](/content/release_notes)
6 |
--------------------------------------------------------------------------------
/docs/content/_sidebar.md:
--------------------------------------------------------------------------------
1 | * [Quick Start](/content/quick_start)
2 |
3 | * [API Reference](/content/api_reference)
4 |
5 | * [Release Notes](/content/release_notes)
6 |
--------------------------------------------------------------------------------
/docs/content/api/_sidebar.md:
--------------------------------------------------------------------------------
1 | * [Quick Start](/content/quick_start)
2 |
3 | * [API Reference](/content/api_reference)
4 | * [Components](/content/api/components)
5 | * [Paths](/content/api/paths)
6 |
7 | * [Release Notes](/content/release_notes)
8 |
--------------------------------------------------------------------------------
/docs/content/api/components.md:
--------------------------------------------------------------------------------
1 | # Components
2 |
3 | ## Responses
4 |
5 | ### Success :id=responsessuccess
6 | > Generated PDF file.
7 |
8 |
9 | * * *
10 |
11 | ### BadRequest :id=responsesbadrequest
12 | > Bad request.
13 |
14 | **Content Type**: application/json
15 |
16 | **Response Type:** Array<Object>
17 |
18 | | Name | Type | Required | Nullable | Description |
19 | | ---- | ---- | -------- | -------- | ----------- |
20 | | value | Object | false | false | |
21 | | value.code | String | false | false | |
22 | | value.message | String | false | false | |
23 | | children | Array | false | false | |
24 |
25 | **Example**:
26 |
27 | ```json
28 | [
29 | {
30 | "value": {
31 | "code": "PRINT_FAILED_NO_HTML_LAYOUT",
32 | "message": "Failed to print PDF, missing html layout."
33 | },
34 | "children": []
35 | }
36 | ]
37 | ```
38 |
39 | * * *
40 |
41 | ### ServerError :id=responsesservererror
42 | > Server error.
43 |
44 | **Content Type**: application/json
45 |
46 | **Response Type:** Array<Object>
47 |
48 | | Name | Type | Required | Nullable | Description |
49 | | ---- | ---- | -------- | -------- | ----------- |
50 | | value | Object | false | false | |
51 | | value.code | String | false | false | |
52 | | value.message | String | false | false | |
53 | | children | Array | false | false | |
54 |
55 | **Example**:
56 |
57 | ```json
58 | [
59 | {
60 | "value": {
61 | "code": "REQUEST_GENERAL_FAILURE",
62 | "message": "An attempt to print html page failed for unspecified reason(s)."
63 | },
64 | "children": []
65 | }
66 | ]
67 | ```
68 |
69 | * * *
70 |
71 |
72 |
--------------------------------------------------------------------------------
/docs/content/api/paths.md:
--------------------------------------------------------------------------------
1 | # Paths
2 |
3 | ## POST /print
4 |
5 | > Prints PDF page from html layout (chrome v92 by default).
6 |
7 | **Summary**: Prints PDF page from html layout (chrome v92 by default).
8 |
9 | #### Request Body
10 |
11 | **Content Type**: application/json
12 |
13 | **Type**: Object
14 |
15 | | Name | Type | Required | Nullable | Description |
16 | | ---- | ---- | -------- | -------- | ----------- |
17 | | source | String | false | false | Optional string to define the source of request |
18 | | html | String | true | false | HTML layout to print |
19 | | settings | Object | false | false | Optional [settings](https://github.com/puppeteer/puppeteer/blob/v5.2.1/docs/api.md#pagepdfoptions) passed to page.pdf() |
20 |
21 | **Example**:
22 |
23 | ```json
24 | {
25 | "source": "crude-oil-price-report",
26 | "html": "
test",
27 | "settings": {
28 | "width": "100px"
29 | }
30 | }
31 | ```
32 |
33 | #### Responses
34 |
35 | **Status Code**: 200 - [Success](/content/api/components?id=responsessuccess)
36 |
37 | * * *
38 |
39 | **Status Code**: 400 - [BadRequest](/content/api/components?id=responsesbadrequest)
40 |
41 | * * *
42 |
43 | **Status Code**: 500 - [ServerError](/content/api/components?id=responsesservererror)
44 |
45 | * * *
46 |
47 |
--------------------------------------------------------------------------------
/docs/content/api_reference.md:
--------------------------------------------------------------------------------
1 | # API Reference
2 |
3 | ## PDF generator API 2.1.0 {docsify-ignore}
4 |
5 | > PDF generator API
6 |
7 | ## OpenAPI Definition {docsify-ignore}
8 |
9 | [Download](static/openapi.yml)
10 |
11 | ## Contents {docsify-ignore}
12 |
13 | * [Components](#Components)
14 | * [Paths](#Paths)
15 |
16 |
17 | ## Components {docsify-ignore}
18 |
19 | ### Responses
20 |
21 | * [Success](/content/api/components?id=responsesSuccess)
22 | * [BadRequest](/content/api/components?id=responsesBadRequest)
23 | * [ServerError](/content/api/components?id=responsesServerError)
24 |
25 |
26 | ## Paths {docsify-ignore}
27 |
28 | * [POST /print](/content/api/paths?id=post-print)
29 |
--------------------------------------------------------------------------------
/docs/content/concepts/_sidebar.md:
--------------------------------------------------------------------------------
1 | * [Quick Start](/content/quick_start)
2 |
3 | * [API Reference](/content/api_reference)
4 |
5 | * [Release Notes](/content/release_notes)
6 |
--------------------------------------------------------------------------------
/docs/content/quick_start.md:
--------------------------------------------------------------------------------
1 | ## Overview
2 |
3 | **This software deploys a web service using AWS infrastructure with endpoints that convert HTML documents into PDF documents.**
4 |
5 | ## Requirements
6 |
7 | * Create an [Amazon Web Services](https://aws.amazon.com/) account — sign up [here](https://portal.aws.amazon.com/billing/signup#/start).
8 | * Install the command line tools for your AWS account — here are the [instructions](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html).
9 | * Install [Node.js](https://nodejs.org/en/) — we recommend using the [Node Version Manager](https://github.com/nvm-sh/nvm).
10 | * Install the [Yarn](https://yarnpkg.com/) package management tool — here are the [instructions](https://classic.yarnpkg.com/en/docs/install).
11 | * Install the [Serverless](https://www.serverless.com/) framework — here are the [instructions](https://www.serverless.com/framework/docs/providers/aws/guide/installation/).
12 |
13 | ## Technical Overview
14 |
15 | * A web application is created using the [AWS API Gateway](https://aws.amazon.com/api-gateway/) service.
16 | * Any HTTP requests received by the web application are handled by an [AWS Lambda Function](https://aws.amazon.com/lambda/).
17 | * The Lambda Function loads [Puppeteer](https://developers.google.com/web/tools/puppeteer) and [Chromium](https://www.chromium.org/) from an [AWS Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html).
18 | * The Lambda Function uses Puppeteer and Chromium to convert an HTML document into a PDF file.
19 |
20 | ## Deployment
21 |
22 | From the project's root directory, install the required dependencies.
23 |
24 | ```shell
25 | yarn install
26 | ```
27 |
28 | Then, execute the deployment, as follows:
29 |
30 | ```
31 | yarn deploy:prod
32 | ```
33 |
34 | First, the deployment process will execute a `make` command, building the Lambda Layer package (which houses Puppeteer and Chromium). Then, it will configure AWS services (e.g. API Gateway, Lambda, etc). Obviously, your AWS account must have the sufficient access to perform these operations.
35 |
36 | ## Endpoints
37 |
38 | Your web service exposes one endpoint:
39 |
40 | * ```/print``` - Renders the PDF document using Puppeteer (and Chromium).
41 |
42 | The endpoint expects a JSON document, with the following properties:
43 |
44 | * ```html``` - A required ```String``` which contains the HTML document itself.
45 | * ```source``` - An optional ```String``` describing the document.
46 | * ```settings``` - An optional ```Object``` which contains [puppeteer options](https://github.com/puppeteer/puppeteer/blob/v5.2.1/docs/api.md#pagepdfoptions).
47 |
48 | Here is an example:
49 |
50 | ```json
51 | {
52 | "source": "testing",
53 | "html": "
Hello World
You have converted an HTML document into a PDF file.
"
54 | }
55 | ```
56 |
57 | ## Testing
58 |
59 | Before deployment, you can run the code locally - simulating the AWS infrastructure, as follows:
60 |
61 | ```shell
62 | cd ./packages/api
63 |
64 | sls invoke local -f print --path print/test/print.json
65 | sls invoke local -f print --path print/test/print.5MB.json
66 | ```
67 |
68 | After deployment, you can test the web service by issuing a ```POST``` request to the actual web service. Here is an example cURL command (obviously, you'll need to correct the hostname and stage name).
69 |
70 | ```shell
71 | curl 'https://{api-identifier}.execute-api.us-east-1.amazonaws.com/{stage|prod}/print' \
72 | -X 'POST' \
73 | --output testing.pdf \
74 | --data-binary '{"source":"testing","html":"
Hello World
You have converted an HTML document into a PDF file.
"}'
75 | ```
76 |
77 | ## Limitations
78 |
79 | * The size of the HTML document cannot exceed 10 MB (a limit of API Gateway service).
80 | * The processing time required to generate the PDF file cannot exceed 30 seconds (a limit of API Gateway service).
81 |
82 | In theory, these limits can be overcome. However, additional engineering would be required. At present, there is no plan to make these enhancements.
83 |
--------------------------------------------------------------------------------
/docs/content/release_notes.md:
--------------------------------------------------------------------------------
1 | # Release Notes
2 |
3 | ## 3.0.1
4 | **Major Changes**
5 |
6 | * Updated [Chromium](https://www.chromium.org/) to version 122 (from version 116).
7 | * Updated [Puppeteer](https://pptr.dev/) to version 22 (from version 21).
8 |
9 |
10 | **Technical Enhancements**
11 |
12 | * Updated AWS CodeBuild integration to use Node.js version 20.
13 | * Updated Node.js runtime to `nodejs20.x` for all Lambda functions (and layers).
14 | * Updated the minimum required version of [`serverless`](https://www.serverless.com/).
15 | * Updated dependencies implicitly.
16 |
17 | ## 3.0.0
18 | **Major Changes**
19 |
20 | * Updated [Chromium](https://www.chromium.org/) to version 116 (from version 92).
21 | * Updated [Puppeteer](https://pptr.dev/) to version 21 (from version 10).
22 |
23 | **Bug Fixes**
24 |
25 | * Corrected inability to run on Node.js versions 16 and 18 by swapping [`aws-chrome-lambda`](https://github.com/alixaxel/chrome-aws-lambda) for [`@sparticuz/chromium`](https://github.com/Sparticuz/chromium).
26 |
27 | **Technical Enhancements**
28 |
29 | * Updated Node.js runtime to `nodejs18.x` for all Lambda functions (and layers).
30 | * Updated the minimum required version of [`serverless`](https://www.serverless.com/).
31 | * Updated [Lerna](https://lerna.js.org/) by three major versions.
32 | * Updated other dependencies explicitly and implicitly.
33 |
34 | ## 2.1.1
35 | **Other**
36 |
37 | * Minor corrections to [documentation website](https://barchart.github.io/aws-lambda-pdf-generator/#).
38 | * Regenerated `yarn.lock` file.
39 |
40 | ## 2.1.0
41 | **New Features**
42 |
43 | * Added the `service/version` endpoint to the API.
44 |
45 | **Technical Enhancements**
46 |
47 | * Updated Node.js runtime to version 14.
48 | * Updated AWS CodeBuild to use Node.js version 14.
49 | * Updated the Serverless framework to version 3.
50 | * Updated the [`puppeteer`](https://github.com/puppeteer/puppeteer), [`puppeteer-core`](https://github.com/puppeteer/puppeteer) and [`chrome-aws-lambda`](https://github.com/alixaxel/chrome-aws-lambda) libraries to version 10.1.0. Puppeteer version 14 is available; however, at present the chrome-aws-lambda library does not support any version past 10.1.0. More detail can be found in the [`README.md`](https://github.com/barchart/aws-lambda-pdf-generator/tree/master/packages/api#technical-notes) file for the API.
51 | * Updated various other dependencies.
52 |
53 | ## 2.0.0
54 | **Breaking Changes**
55 |
56 | * Removed `print/v81` and `print/v83` endpoints from the API. Only the `print` endpoint remains.
57 | * Renamed application. Avoid problems by removing previous installations first (see the `sls remove` command).
58 |
59 | **New Features**
60 |
61 | * Generation of PDF files larger than 10 MB is now supported. (using gzip compression or an HTTP 303 response).
62 |
63 | **Technical Enhancements**
64 |
65 | * Converted project to use [Lerna](https://github.com/lerna/lerna) approach.
66 | * Upgraded [Serverless](https://www.serverless.com/) framework to version 2.13.0 (or better).
67 | * Added descriptions for application and functions to `serverless.yml` file.
68 | * Updated Chromium version from `v83` to `v88`.
69 |
70 |
71 | ## 1.1.1
72 | **No Functional Changes**
73 |
74 | * Finalized [Documentation](https://barchart.github.io/aws-lambda-pdf-generator/#/).
75 |
76 | ## 1.1.0
77 | **New Features**
78 |
79 | * Added ```source``` field as part of the request body.
80 |
81 | **Other**
82 |
83 | * Added printer failure types.
84 | * Improved logging.
85 |
86 | ## 1.0.5
87 | **Initial Public Release**
88 |
--------------------------------------------------------------------------------
/docs/content/releases/1.0.5.md:
--------------------------------------------------------------------------------
1 | **Initial Public Release**
--------------------------------------------------------------------------------
/docs/content/releases/1.1.0.md:
--------------------------------------------------------------------------------
1 | **New Features**
2 |
3 | * Added ```source``` field as part of the request body.
4 |
5 | **Other**
6 |
7 | * Added printer failure types.
8 | * Improved logging.
--------------------------------------------------------------------------------
/docs/content/releases/1.1.1.md:
--------------------------------------------------------------------------------
1 | **No Functional Changes**
2 |
3 | * Finalized [Documentation](https://barchart.github.io/aws-lambda-pdf-generator/#/).
--------------------------------------------------------------------------------
/docs/content/releases/2.0.0.md:
--------------------------------------------------------------------------------
1 | **Breaking Changes**
2 |
3 | * Removed `print/v81` and `print/v83` endpoints from the API. Only the `print` endpoint remains.
4 | * Renamed application. Avoid problems by removing previous installations first (see the `sls remove` command).
5 |
6 | **New Features**
7 |
8 | * Generation of PDF files larger than 10 MB is now supported. (using gzip compression or an HTTP 303 response).
9 |
10 | **Technical Enhancements**
11 |
12 | * Converted project to use [Lerna](https://github.com/lerna/lerna) approach.
13 | * Upgraded [Serverless](https://www.serverless.com/) framework to version 2.13.0 (or better).
14 | * Added descriptions for application and functions to `serverless.yml` file.
15 | * Updated Chromium version from `v83` to `v88`.
16 |
--------------------------------------------------------------------------------
/docs/content/releases/2.1.0.md:
--------------------------------------------------------------------------------
1 | **New Features**
2 |
3 | * Added the `service/version` endpoint to the API.
4 |
5 | **Technical Enhancements**
6 |
7 | * Updated Node.js runtime to version 14.
8 | * Updated AWS CodeBuild to use Node.js version 14.
9 | * Updated the Serverless framework to version 3.
10 | * Updated the [`puppeteer`](https://github.com/puppeteer/puppeteer), [`puppeteer-core`](https://github.com/puppeteer/puppeteer) and [`chrome-aws-lambda`](https://github.com/alixaxel/chrome-aws-lambda) libraries to version 10.1.0. Puppeteer version 14 is available; however, at present the chrome-aws-lambda library does not support any version past 10.1.0. More detail can be found in the [`README.md`](https://github.com/barchart/aws-lambda-pdf-generator/tree/master/packages/api#technical-notes) file for the API.
11 | * Updated various other dependencies.
--------------------------------------------------------------------------------
/docs/content/releases/2.1.1.md:
--------------------------------------------------------------------------------
1 | **Other**
2 |
3 | * Minor corrections to [documentation website](https://barchart.github.io/aws-lambda-pdf-generator/#).
4 | * Regenerated `yarn.lock` file.
--------------------------------------------------------------------------------
/docs/content/releases/3.0.0.md:
--------------------------------------------------------------------------------
1 | **Major Changes**
2 |
3 | * Updated [Chromium](https://www.chromium.org/) to version 116 (from version 92).
4 | * Updated [Puppeteer](https://pptr.dev/) to version 21 (from version 10).
5 |
6 | **Bug Fixes**
7 |
8 | * Corrected inability to run on Node.js versions 16 and 18 by swapping [`aws-chrome-lambda`](https://github.com/alixaxel/chrome-aws-lambda) for [`@sparticuz/chromium`](https://github.com/Sparticuz/chromium).
9 |
10 | **Technical Enhancements**
11 |
12 | * Updated Node.js runtime to `nodejs18.x` for all Lambda functions (and layers).
13 | * Updated the minimum required version of [`serverless`](https://www.serverless.com/).
14 | * Updated [Lerna](https://lerna.js.org/) by three major versions.
15 | * Updated other dependencies explicitly and implicitly.
--------------------------------------------------------------------------------
/docs/content/releases/3.0.1.md:
--------------------------------------------------------------------------------
1 | **Major Changes**
2 |
3 | * Updated [Chromium](https://www.chromium.org/) to version 122 (from version 116).
4 | * Updated [Puppeteer](https://pptr.dev/) to version 22 (from version 21).
5 |
6 | **Technical Enhancements**
7 |
8 | * Updated AWS CodeBuild integration to use Node.js version 20.
9 | * Updated Node.js runtime to `nodejs20.x` for all Lambda functions (and layers).
10 | * Updated the minimum required version of [`serverless`](https://www.serverless.com/).
11 | * Updated dependencies implicitly.
--------------------------------------------------------------------------------
/docs/content/releases/_sidebar.md:
--------------------------------------------------------------------------------
1 | * [Quick Start](/content/quick_start)
2 |
3 | * [API Reference](/content/api_reference)
4 |
5 | * [Release Notes](/content/release_notes)
6 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Document
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/docs/static/openapi.yml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.1
2 |
3 | info:
4 | title: PDF generator API
5 | description: PDF generator API
6 | version: 2.1.0
7 |
8 | components:
9 | responses:
10 | Success:
11 | description: Generated PDF file.
12 | content:
13 | application/pdf:
14 | schema:
15 | type: string
16 | format: binary
17 |
18 | BadRequest:
19 | description: Bad request.
20 | content:
21 | application/json:
22 | schema:
23 | type: array
24 | items:
25 | type: object
26 | properties:
27 | value:
28 | type: object
29 | properties:
30 | code:
31 | type: string
32 | example: PRINT_FAILED_NO_HTML_LAYOUT
33 | message:
34 | type: string
35 | example: Failed to print PDF, missing html layout.
36 | children:
37 | type: array
38 | example: []
39 | items: {}
40 |
41 | ServerError:
42 | description: Server error.
43 | content:
44 | application/json:
45 | schema:
46 | type: array
47 | items:
48 | type: object
49 | properties:
50 | value:
51 | type: object
52 | properties:
53 | code:
54 | type: string
55 | example: REQUEST_GENERAL_FAILURE
56 | message:
57 | type: string
58 | example: An attempt to print html page failed for unspecified reason(s).
59 | children:
60 | type: array
61 | example: []
62 | items: {}
63 |
64 | tags:
65 | - name: Pdf
66 |
67 | paths:
68 | /print:
69 | post:
70 | summary: Prints PDF page from html layout (chrome v92 by default).
71 | description: Prints PDF page from html layout (chrome v92 by default).
72 | tags:
73 | - Pdf
74 | requestBody:
75 | content:
76 | application/json:
77 | schema:
78 | type: object
79 | properties:
80 | source:
81 | type: string
82 | description: Optional string to define the source of request
83 | example: crude-oil-price-report
84 | html:
85 | type: string
86 | description: HTML layout to print
87 | example: 'test'
88 | settings:
89 | type: object
90 | description: 'Optional [settings](https://github.com/puppeteer/puppeteer/blob/v5.2.1/docs/api.md#pagepdfoptions) passed to page.pdf()'
91 | example: { width: '100px' }
92 | required:
93 | - html
94 | responses:
95 | '200':
96 | $ref: '#/components/responses/Success'
97 | '400':
98 | $ref: '#/components/responses/BadRequest'
99 | '500':
100 | $ref: '#/components/responses/ServerError'
101 |
--------------------------------------------------------------------------------
/docs/styles/override.css:
--------------------------------------------------------------------------------
1 | .sidebar .app-name {
2 | text-align: left;
3 | margin-left: 15px;
4 | }
5 |
6 | .sidebar ul li {
7 | font-size: 14px;
8 | color: #505d6b;
9 | }
10 |
11 | h2#contents + ul p {
12 | margin: 0;
13 | }
14 |
15 | main section.content {
16 | padding-top: 0;
17 | }
18 |
19 | iframe#swagger {
20 | display: block;
21 | width: 100%;
22 | height: 100vh;
23 | border: none;
24 | }
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "npmClient": "yarn",
3 | "packages": [
4 | "packages/*"
5 | ],
6 | "version": "3.0.1",
7 | "useWorkspaces": true
8 | }
9 |
--------------------------------------------------------------------------------
/openapi.yml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.1
2 |
3 | info:
4 | title: PDF generator API
5 | description: PDF generator API
6 | version: 2.1.0
7 |
8 | components:
9 | responses:
10 | Success:
11 | description: Generated PDF file.
12 | content:
13 | application/pdf:
14 | schema:
15 | type: string
16 | format: binary
17 |
18 | BadRequest:
19 | description: Bad request.
20 | content:
21 | application/json:
22 | schema:
23 | type: array
24 | items:
25 | type: object
26 | properties:
27 | value:
28 | type: object
29 | properties:
30 | code:
31 | type: string
32 | example: PRINT_FAILED_NO_HTML_LAYOUT
33 | message:
34 | type: string
35 | example: Failed to print PDF, missing html layout.
36 | children:
37 | type: array
38 | example: []
39 | items: {}
40 |
41 | ServerError:
42 | description: Server error.
43 | content:
44 | application/json:
45 | schema:
46 | type: array
47 | items:
48 | type: object
49 | properties:
50 | value:
51 | type: object
52 | properties:
53 | code:
54 | type: string
55 | example: REQUEST_GENERAL_FAILURE
56 | message:
57 | type: string
58 | example: An attempt to print html page failed for unspecified reason(s).
59 | children:
60 | type: array
61 | example: []
62 | items: {}
63 |
64 | tags:
65 | - name: Pdf
66 |
67 | paths:
68 | /print:
69 | post:
70 | summary: Prints PDF page from html layout (chrome v92 by default).
71 | description: Prints PDF page from html layout (chrome v92 by default).
72 | tags:
73 | - Pdf
74 | requestBody:
75 | content:
76 | application/json:
77 | schema:
78 | type: object
79 | properties:
80 | source:
81 | type: string
82 | description: Optional string to define the source of request
83 | example: crude-oil-price-report
84 | html:
85 | type: string
86 | description: HTML layout to print
87 | example: 'test'
88 | settings:
89 | type: object
90 | description: 'Optional [settings](https://github.com/puppeteer/puppeteer/blob/v5.2.1/docs/api.md#pagepdfoptions) passed to page.pdf()'
91 | example: { width: '100px' }
92 | required:
93 | - html
94 | responses:
95 | '200':
96 | $ref: '#/components/responses/Success'
97 | '400':
98 | $ref: '#/components/responses/BadRequest'
99 | '500':
100 | $ref: '#/components/responses/ServerError'
101 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@barchart/aws-lambda-pdf-generator",
3 | "workspaces": [
4 | "packages/*"
5 | ],
6 | "repository": {
7 | "type": "git",
8 | "url": "git+ssh://git@github.com/barchart/barchart/aws-lambda-pdf-generator.git"
9 | },
10 | "scripts": {
11 | "clean": "lerna clean --yes && rm -rf node_modules",
12 | "lint": "lerna run lint --stream",
13 | "preversion": "git diff --exit-code",
14 | "release": "lerna version -m 'Release. Bump version number %v' --tag-version-prefix='' --force-publish",
15 | "deploy:stage": "lerna run deploy:stage --stream",
16 | "deploy:prod": "lerna run deploy:prod --stream"
17 | },
18 | "devDependencies": {
19 | "jshint": "^2.13.6",
20 | "lerna": "^6.6.2",
21 | "serverless-apigw-binary": "^0.4.4",
22 | "serverless-webpack": "^5.5.0",
23 | "webpack": "^5.11.1"
24 | },
25 | "license": "MIT",
26 | "private": true
27 | }
28 |
--------------------------------------------------------------------------------
/packages/api/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: clean
2 |
3 | .DEFAULT_GOAL := all
4 |
5 | CHROME_REPO=https://github.com/Sparticuz/chromium.git
6 | LAYERS_FOLDER=layers
7 |
8 | all: ${LAYERS_FOLDER}/chromium-v122.zip
9 |
10 | ${LAYERS_FOLDER}/chromium-v122.zip:
11 | @echo 'Downloading...' \
12 | && git clone $(CHROME_REPO) chromium-aws-lambda --depth 1 --branch v122.0.0 \
13 | && echo 'Making .zip archive...' \
14 | && cd chromium-aws-lambda \
15 | && rm -rf node_modules \
16 | && npm i \
17 | && make chromium-aws-lambda.zip && mkdir -p ./../layers && mv chromium-aws-lambda.zip ./../${LAYERS_FOLDER}/chromium-v122.zip \
18 | && echo 'Removing unnecessary stuff...' \
19 | && cd ../ && rm -rf chromium-aws-lambda \
20 | && echo 'Done'
21 |
22 | clean:
23 | rm -rf layers && rm -rf chromium-aws-lambda
24 |
--------------------------------------------------------------------------------
/packages/api/README.md:
--------------------------------------------------------------------------------
1 | # @barchart/serverless-pdf-generator
2 |
3 | ### Serverless
4 |
5 | This project uses the [Serverless](https://serverless.com/) framework for testing and deployment.
6 |
7 | #### Installation
8 |
9 | ```shell
10 | yarn global add serverless
11 | ```
12 |
13 | #### Deployment
14 |
15 | Deploy the service from the project's root directory.
16 |
17 | ```shell
18 | cd ./../..
19 | yarn install
20 | yarn run deploy:[stage|prod]
21 | ```
22 |
23 | ### Testing
24 |
25 | #### Local Testing
26 |
27 | ```shell
28 | sls invoke local -f print --path print/test/print.json
29 | sls invoke local -f print --path print/test/print.5MB.json
30 |
31 | sls invoke local -f serviceRead --path service/test/version.json
32 | ```
33 |
34 | #### Remote Testing
35 |
36 | ```shell
37 | curl 'https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/stage/print' \
38 | -X 'POST' \
39 | --output testing.pdf \
40 | --data-binary '{"source":"testing","html":"
Hello World
You have converted an HTML document into a PDF file.