IronPDF 故障排除 AWS Lambda / Amazon Linux 2 AWS Lambda IronPDF on Amazon Linux 2 Curtis Chau 更新:2025年8月31日 下載 IronPDF NuGet 下載 DLL 下載 Windows Installer 開始免費試用 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以管理者/root 身分安裝) 此資訊也顯示在我們的網站上 - 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 進程不可用"的訊息,則可能是安裝程式未以管理員權限執行。 請嘗試使用管理員/root權限再次執行該軟體。 或者,將以下內容新增至您的 Dockerfile 中: RUN chmod 755 "runtimes/linux-x64/native/IronCefSubprocess" Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 17,803,474 | 版本: 2026.3 剛剛發布 開始免費試用 免費 NuGet 下載 總下載量:17,803,474 查看許可證 還在滾動嗎? 想快速取得證據? PM > Install-Package IronPdf 運行範例看著你的HTML程式碼變成PDF檔。 免費 NuGet 下載 總下載量:17,803,474 查看許可證