@bayaweaver/report-weaver-lambda
v1.0.0
Published
To avoid long-running, all dependencies of the `@bnc/report` must be placed in a Lambda Layer. **Install 7z**. Then open PowerShell and open GitBash Terminal:
Readme
Packaging for Lambda
To avoid long-running, all dependencies of the @bnc/report must be placed in a Lambda Layer. Install 7z. Then open
PowerShell and open GitBash Terminal:
& "C:\Program Files\Git\git-bash.exe"Then run
npm run buildAs a result, two files will appear, the dependencies.zip and the handler.zip. The firs one is dedicated to a Lambda
Layer, the second one - to a Lambda itself. Conceptually, a pipeline of the project
bnc-report-generator-environment does the same.
Request
Below is an example of a cURL command to initiate the report generation:
curl --location --request POST 'https://<lambda-url>' \
--header 'X-Api-Key: <key-value>' \
--header 'Content-Type: application/json; charset=UTF-8' \
--data-raw '{
"template": "<table><tr><td style='\''border: solid'\''>{{greeting}}</td></tr></table>",
"data": {
"greeting": "Hello, cell A1"
},
"outputFormat": "XLSX",
"fileName": "my-report.pdf",
"callbackUrl": "https://<callback-url>"
}'Parameters:
X-Api-Key- A header which is responsible to secure invocations.template- A HTML template that will be processed by the Nunjucks template engine. template engine.data- The data to be applied to the template. This can be provided as either a plain JSON object or a JSON-formatted string.outputFormat- The expected format of the output file. Possible values:PDF,XLSX. Not required. A default value:PDF.fileName- A file name which must be assigned to a generated file. Optional.callbackUrl- The URL that will be called once the file generation is complete.
Limitations:
The maximum allowed size for the request is 6 MB. This limitation is imposed by the Lambda specification. Therefore, it is recommended to pass both the template and data JSON in a compressed/minified format.
Response
In response to a request, the Report Generator will return the following:
{
"reference": "5c9527aa-7d83-487b-b6cd-d905c4a3ef89"
}The reference value can later be associated with the one returned in a callback, paired with a file link (see
Callback below).
Callback
After the report is generated, the Lambda function sends a POST request to the specified callback URL.
{
"reference": "5c9527aa-7d83-487b-b6cd-d905c4a3ef89",
"fileLink": "https://bnc-reports.s3.eu-north-1.amazonaws.com/866f3773-48dd-484a-b4eb-ee203972b536.xlsx?X-Amz-..."
}fileLink- A link to the generated report file. The link is temporary and remains active for only 30 minutes. Moreover, the file itself exists only 1 day and then is deleted. If any error occurred, this property is not present.error- An error message in case the report was not generated. It is present only if any error occurred.
