简体   繁体   English

如何在AWS lambda、node.js v18中通过chromium生成PDF

[英]How to generate PDF by chromium in AWS lambda, node.js v18

I am trying to generate PDF by @sparticuz/chromium using AWS lambda, node.js v18, layer and architecture: x86_64.我正在尝试通过@sparticuz/chromium使用 AWS lambda、node.js v18、层和架构生成 PDF:x86_64。

I get the error:我收到错误:

Runtime.ImportModuleError: Error: Cannot find module '@sparticuz/chromium' Runtime.ImportModuleError:错误:找不到模块“@sparticuz/chromium”

Layer:层:

{
  "name": "chrome_layer",
  "dependencies": {
    "@sparticuz/chromium": "108.0.1",
    "puppeteer-core": "18.0.5"
  }
}

Code:代码:

const chromium = require('@sparticuz/chromium')
const puppeteer = require('puppeteer-core')

const browser = await puppeteer.launch({
      args: chromium.args,
      executablePath: await chromium.executablePath,
    })

I had a similar problem.我有一个类似的问题。 In my case I was trying to deploy the lambda with AWS CDK, without a separate layer.在我的例子中,我尝试使用 AWS CDK 部署 lambda,没有单独的层。

When you create the NodejsFunction, inside NodejsFunctionProps, pass 2 things:当您在 NodejsFunctionProps 中创建 NodejsFunction 时,传递 2 个东西:

  1. the package-lock.json file: package-lock.json 文件:

    depsLockFilePath: 'src/your-lambda-path/package-lock.json', depsLockFilePath: 'src/your-lambda-path/package-lock.json',

  2. make sure the @sparticuz/chromium node module won't be bundled as a single file, but rather passed as is in node_modules folder确保 @sparticuz/chromium 节点模块不会被捆绑为单个文件,而是按原样在 node_modules 文件夹中传递

    bundling.nodeModules: [ '@sparticuz/chromium', ], bundling.nodeModules: [ '@sparticuz/chromium', ],

This way the binary for chromium will be installed.这样就会安装 chromium 的二进制文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node.js AWS Lambda 不等待任何事情 - Node.js AWS Lambda not waiting for anything AWS Lambda HTTP POST 请求 (Node.js) - AWS Lambda HTTP POST Request (Node.js) Aws Lambda - 一起使用 java11 和 node.js - Aws Lambda - Using java11 and node.js together 如何在基础 AWS Lambda Node.js Dockerfile 图像中安装依赖项 - How to install dependencies in base AWS Lambda Node.js Dockerfile image 使用 AWS CDK python 部署 node.js lambda - Deploying node.js lambda with AWS CDK python 使用 AWS Lambda(node.js) 扫描 DynamoDB 时没有结果 - No results when scanning DynamoDB with AWS Lambda(node.js) AWS Lambda - 使用 Node.js 获取路径参数 - AWS Lambda - Getting path parameters using Node.js 如何在 AWS lambda 中使用 HTML 模板引擎和 Node.js function? - How to use an HTML templating engine with a Node.js function in an AWS lambda? 如何从 boto3 为 python 中的 node.js 应用程序创建和部署 AWS lambda - How to create and deploy AWS lambda from boto3 for node.js app in python 如何使用无服务器框架通过 AWS API 网关在 Node.js 中编写的 AWS Lambda function 上返回错误? - How do I return errors on an AWS Lambda function written in Node.js through the AWS API Gateway using the Serverless framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM