英文:
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
我们可以按照以下步骤部署具有依赖项的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文件。
参考链接:
- 使用Node.js构建Lambda函数
- 在Web应用程序中选择AWS Lambda数据存储选项
- Amazon S3 Node.js示例
- 使用.zip文件存档部署Node.js Lambda函数
- AWS无服务器应用程序模型(AWS SAM)
希望这有所帮助。
英文:
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 of512 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 packagepdffiller
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 :
- Building Lambda functions with NodeJs
- Choosing between AWS Lambda data storage options in web apps
- Amazon S3 Node.js Examples
- Deploy Node.js Lambda functions with .zip file archives
- AWS Serverless Application Model
Hope this helps
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论