IronPDF Lambda部署中的缺少相依性

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPDF在部署到AWS Lambda時無法初始化,產生以下類似錯誤:

IronPDF failed to start: required native binaries not found at the expected path.
Unable to load shared library or one of its dependencies.
Error: Required IronPDF native dependencies were not found in the deployment package.

Lambda部署中缺少原生相依性是由以下一個或多個原因造成的:

  • 缺少權限:Lambda執行角色或檔案系統路徑缺少IronPDF所需的讀/寫/執行權限。
  • 缺少原生二進位文件:部屬包中未包含原生IronPDF程式庫。
  • Dockerfile不正確:Dockerfile未安裝Lambda基礎映像所需的正確OS級相依性。

解決方案

切換到IronPdf.Slim NuGet套件。 與完整的IronPDF套件不同,IronPdf.Slim會在運行時自動下載檢測到的基礎映像所需的正確原生二進位文件,消除了手動捆綁平台專用二進位文件的需要:

// NuGet: IronPdf.Slim
// IronPdf.Slim selects and downloads the appropriate native runtime
// for the Lambda execution environment automatically.
IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY");

var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Hello from Lambda</h1>");
pdf.SaveAs("/tmp/output.pdf");
// NuGet: IronPdf.Slim
// IronPdf.Slim selects and downloads the appropriate native runtime
// for the Lambda execution environment automatically.
IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY");

var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Hello from Lambda</h1>");
pdf.SaveAs("/tmp/output.pdf");
' NuGet: IronPdf.Slim
' IronPdf.Slim selects and downloads the appropriate native runtime
' for the Lambda execution environment automatically.
IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY")

Dim renderer As New ChromePdfRenderer()
Dim pdf = Await renderer.RenderHtmlAsPdfAsync("<h1>Hello from Lambda</h1>")
pdf.SaveAs("/tmp/output.pdf")
$vbLabelText   $csharpLabel

直接在Lambda中測試:不要依賴本地測試來驗證原生相依性解決方案。 專案在本地運行時會下載與Windows相容或與主機OS相容的二進位文件,而不是與Lambda相容的二進位文件,導致誤判為通過。

從AWS檢索日誌檔案以獲取診斷細節,當在切換到IronPdf.Slim後問題仍然存在時。 在第一次呼叫IronPDF之前啟用日誌記錄:

IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LogFilePath = "/tmp/ironpdf.log";
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LogFilePath = "/tmp/ironpdf.log";
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
Imports IronPdf.Logging

Logger.EnableDebugging = True
Logger.LogFilePath = "/tmp/ironpdf.log"
Logger.LoggingMode = Logger.LoggingModes.All
$vbLabelText   $csharpLabel

在您的支援請求中附加/tmp/ironpdf.log和Lambda CloudWatch日誌輸出。另請參閱:將IronPDF部署到AWS Lambda與Docker如何獲取IronPDF在AWS中的日誌檔案

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備開始了嗎?
Nuget 下載 20,088,359 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

還在捲動嗎?

想快速獲得證明嗎? PM > Install-Package IronPdf
執行範例 看您的HTML變成PDF。