IronPDF 故障排除 AWS Lambda / Amazon Linux 2 亚马逊 Linux 2 上的AWS Lambda IronPDF. Curtis Chau 已更新:2025年8月31日 下载 IronPDF NuGet 下载 DLL 下载 Windows 安装程序 免费试用 LLM副本 LLM副本 将页面复制为 Markdown 格式,用于 LLMs 在 ChatGPT 中打开 向 ChatGPT 咨询此页面 在双子座打开 向 Gemini 询问此页面 在 Grok 中打开 向 Grok 询问此页面 打开困惑 向 Perplexity 询问有关此页面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 复制链接 电子邮件文章 This article was translated from English: Does it need improvement? Translated View the article in English AWS Lambda / Amazon Linux 2(以管理员/根用户身份安装 IronPdf.Linux) 这些信息也在我们的网站上显示 - AWS Lambda IronPDF 指南 AWS 指导 查看 AWS .NET 5 Lambda 支持和容器镜像 创建并使用以下 Dockerfile: # Use the .NET 5 AWS Lambda runtime as the base image FROM public.ecr.aws/lambda/dotnet:5.0 WORKDIR /var/task # Install the necessary dependencies for IronPDF RUN yum install -y pango.x86_64 \ libXcomposite.x86_64 \ libXcursor.x86_64 \ libXdamage.x86_64 \ libXext.x86_64 \ libXi.x86_64 \ libXtst.x86_64 \ cups-libs.x86_64 \ libXScrnSaver.x86_64 \ libXrandr.x86_64 \ GConf2.x86_64 \ alsa-lib.x86_64 \ atk.x86_64 \ gtk3.x86_64 \ ipa-gothic-fonts \ xorg-x11-fonts-100dpi \ xorg-x11-fonts-75dpi \ xorg-x11-utils \ xorg-x11-fonts-cyrillic \ xorg-x11-fonts-Type1 \ xorg-x11-fonts-misc \ glibc-devel.x86_64 \ at-spi2-atk.x86_64 \ mesa-libgbm.x86_64 # This COPY command copies the .NET Lambda project's build artifacts from the host machine into the image. COPY "bin/Release/lambda-publish" . 将 IronPdf.Linux 包添加到您的解决方案中。 修改 _FunctionHandler 代码 - 此示例将从网页( IronPDF )创建 PDF 并将其保存到 /tmp。 要查看此 PDF,必须将其上传到另一个服务,例如 S3。(此处有官方 AWS 示例 - AWS S3 基础知识) // Define the function handler for AWS Lambda public Casing FunctionHandler(string input, ILambdaContext context) { try { // Start logging the function process with input details context.Logger.LogLine($"START FunctionHandler RequestId: {context.AwsRequestId} Input: {input}"); var awsTmpPath = @"/tmp/"; // AWS temporary storage path // Optional: Enable debugging for IronPdf // IronPdf.Logging.Logger.EnableDebugging = true; // IronPdf.Logging.Logger.LogFilePath = awsTmpPath; // IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All; // Set your license key for IronPDF IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY"; // Configuration for IronPDF rendering IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled; IronPdf.Installation.DefaultRenderingEngine = IronPdf.Rendering.PdfRenderingEngine.Chrome; Environment.SetEnvironmentVariable("TEMP", awsTmpPath, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("TMP", awsTmpPath, EnvironmentVariableTarget.Process); IronPdf.Installation.TempFolderPath = awsTmpPath; IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath; IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true; context.Logger.LogLine($"Creating IronPdf.ChromePdfRenderer"); // Create instance of ChromePdfRenderer and render PDF from URL var renderer = new IronPdf.ChromePdfRenderer(); context.Logger.LogLine($"Rendering PDF"); using var pdfDoc = renderer.RenderUrlAsPdf("https://ironpdf.com/"); var guid = Guid.NewGuid(); var fileName = $"/tmp/{input}_{guid}.pdf"; // Name for the PDF file // Save the rendered PDF document context.Logger.LogLine($"Saving PDF name : {fileName}"); pdfDoc.SaveAs(fileName); // Here you can upload the saved PDF file to anywhere such as AWS S3. context.Logger.LogLine($"COMPLETE!"); } catch (Exception e) { // Log errors if any occur context.Logger.LogLine($"[ERROR] FunctionHandler : {e.Message}"); } // Return a new instance of Casing with lower and upper case input strings return new Casing(input?.ToLower(), input?.ToUpper()); } // Casing record to hold lower and upper case strings public record Casing(string Lower, string Upper); // Define the function handler for AWS Lambda public Casing FunctionHandler(string input, ILambdaContext context) { try { // Start logging the function process with input details context.Logger.LogLine($"START FunctionHandler RequestId: {context.AwsRequestId} Input: {input}"); var awsTmpPath = @"/tmp/"; // AWS temporary storage path // Optional: Enable debugging for IronPdf // IronPdf.Logging.Logger.EnableDebugging = true; // IronPdf.Logging.Logger.LogFilePath = awsTmpPath; // IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All; // Set your license key for IronPDF IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY"; // Configuration for IronPDF rendering IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled; IronPdf.Installation.DefaultRenderingEngine = IronPdf.Rendering.PdfRenderingEngine.Chrome; Environment.SetEnvironmentVariable("TEMP", awsTmpPath, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("TMP", awsTmpPath, EnvironmentVariableTarget.Process); IronPdf.Installation.TempFolderPath = awsTmpPath; IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath; IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true; context.Logger.LogLine($"Creating IronPdf.ChromePdfRenderer"); // Create instance of ChromePdfRenderer and render PDF from URL var renderer = new IronPdf.ChromePdfRenderer(); context.Logger.LogLine($"Rendering PDF"); using var pdfDoc = renderer.RenderUrlAsPdf("https://ironpdf.com/"); var guid = Guid.NewGuid(); var fileName = $"/tmp/{input}_{guid}.pdf"; // Name for the PDF file // Save the rendered PDF document context.Logger.LogLine($"Saving PDF name : {fileName}"); pdfDoc.SaveAs(fileName); // Here you can upload the saved PDF file to anywhere such as AWS S3. context.Logger.LogLine($"COMPLETE!"); } catch (Exception e) { // Log errors if any occur context.Logger.LogLine($"[ERROR] FunctionHandler : {e.Message}"); } // Return a new instance of Casing with lower and upper case input strings return new Casing(input?.ToLower(), input?.ToUpper()); } // Casing record to hold lower and upper case strings public record Casing(string Lower, string Upper); $vbLabelText $csharpLabel 增加内存和超时 - IronPDF 需要比 Lambda 默认值更多的时间和内存。 这可以在 aws-lambda-tools-defaults.json 中进行配置。 调整这些值以匹配您的函数需求。 在此示例中,我们设置为 512 MB 和 330 秒: "function-memory-size": 512, "function-timeout": 330, 此配置也可以通过 Lambda 控制台更新 - AWS Lambda 内存配置。 请按照文档的最后部分发布并尝试 Lambda 函数 AWS .NET 5 Lambda 支持和容器镜像 Lambda 函数还可以通过 Lambda 控制台调用,AWS Lambda 控制台 或通过 Visual Studio 使用 AWS Toolkit for Visual Studio 进行调用。 如果收到"GPU 进程无法使用"消息,可能是安装时未使用管理员权限运行。 请尝试以管理员/根用户身份重新运行软件。 或者,将以下内容添加到您的 Dockerfile 中: RUN chmod 755 "runtimes/linux-x64/native/IronCefSubprocess" Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 准备开始了吗? Nuget 下载 17,803,474 | 版本: 2026.3 刚刚发布 免费试用 免费 NuGet 下载 总下载量:17,803,474 查看许可证 还在滚动吗? 想快速获得证据? PM > Install-Package IronPdf 运行示例看着你的HTML代码变成PDF文件。 免费 NuGet 下载 总下载量:17,803,474 查看许可证