AWS Lambda PDF填充集成

huangapple go评论65阅读模式
英文:

AWS lambda PDF Filler integration

问题

我是新手AWS。 有人可以告诉我如何使用AWS Lambda集成PDFFiller吗?我看过一个链接。在此输入链接描述

这非常容易理解。但我不知道如何集成。我进行了研究但没有找到任何链接。有人可以提供一些解决方案或链接吗?

提前感谢。

英文:

I am new to AWS. Can anyone tell me how to integrate PDFFiller using AWS lambda. I have seen one url. enter link description here

It is very easy to understand. But I don't know how to integrate. I did R&D but didn't get any urls. Can anyone provide some solutions or urls.

Thanks in advance.

答案1

得分: 0

查看使用Node.js构建Lambda函数

我们可以按照以下步骤部署具有依赖项的Lambda函数

1 - 初始化Node.js项目

npm init

2 - 安装PdfFiller包

npm install pdffiller --save

3 - 编写您的index.js文件

const pdfFiller = require('pdffiller');

exports.handler = async function (event, context) {

    const sourcePDF = 'sample.pdf';
    var destinationPDF =  "/tmp/test_complete.pdf";

    var data = {
        "demo" : "demo-val"
    };

    pdfFiller.fillFormWithOptions( sourcePDF, destinationPDF, data, true,"/tmp",function(err) {
        if (err) throw err;
        console.log("In callback (we're done).");
    });
     


    // TODO implement
    const response = {
        statusCode: 200,
        body: "success",
    };
    return response;
};

4 - 创建一个zip文件

您的项目结构将如下所示

~/my-function
├── index.js
└── node_modules
    ├── pdffiller

将整个项目制作成zip文件(应包括node_modules)

5 - 部署

最后,您可以部署它。查看如何部署为zip

确保的因素

  • sourcePDF:目前,源pdf已放置在项目本身中。这不是一个完美的方法;您可以从其他来源加载它,例如s3,外部存储等。

  • destinationPDF,以/tmp为前缀:Lambda执行环境为您的代码提供了一个用于存储的文件系统,位置在/tmp。此空间的固定大小为512 MB。当您需要存储目标pdf时,可以将文件系统附加到Lambda,请参阅。或者其他来源,比如s3。

  • 为什么使用fillFormWithOptions:由于包pdffiller会创建一个临时pdf文件,(查看index.js文件),与其他文件系统不同,Lambda使用/tmp来存储文件(没有任何文件系统附加)。必须提及Lambda生成临时pdf的路径。否则,在这里执行会失败,因为它无法创建临时pdf文件。

参考链接:

希望这有所帮助。

英文:

See Building Lambda functions with NodeJs

We can deploy the lambda with dependencies as follows

1 - Initialise the Node.js Project

npm init

2 - Install the PdfFiller package

npm install pdffiller --save

3 - Write your index.js file

const pdfFiller = require('pdffiller');

exports.handler = async function (event, context) {

    const sourcePDF = 'sample.pdf';
    var destinationPDF =  "/tmp/test_complete.pdf";

    var data = {
        "demo" : "demo-val"
    };

    pdfFiller.fillFormWithOptions( sourcePDF, destinationPDF, data, true,"/tmp",function(err) {
        if (err) throw err;
        console.log("In callback (we're done).");
    });
     


    // TODO implement
    const response = {
        statusCode: 200,
        body: "success",
    };
    return response;
};

4 - Make a zip

You'll have project structure as

~/my-function
├── index.js
└── node_modules
    ├── pdffiller

Make your entire project as zip (should include node_modules)

5 - Deploying

And finally you can deploy it. See how to deploy as zip

Factors to ensure

  • sourcePDF : Currently, the source pdf has been put within the project itself. This is not a perfect method; you may load it from another source, such as s3, external storage, etc.

  • destinationPDF , /tmp as prefix : The Lambda execution environment provides a file system for your code to use at /tmp. This space has a fixed size of 512 MB. You can attach file system with your lambda when you need to store the destination pdf See. Or another sources such as s3.

  • Why used fillFormWithOptions : As the package pdffiller creating a temporary pdf file,(see index.js file) unlike with the other fie system,lambda uses /tmp for storing the files (without any file-system attachment).
    It is necessary to mention the temporary pdf generate path with lambda. Else, the execution will fail at here, as it couldn't be able to create the temp pdf file.

Reference Links :

Hope this helps

huangapple
  • 本文由 发表于 2023年6月2日 15:03:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76387857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定